Skip to content

Commit 6578546

Browse files
committed
Use Prophecy for mocks
1 parent 371139e commit 6578546

10 files changed

+240
-404
lines changed

tests/GraphNodes/AbstractGraphNode.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,31 +23,29 @@
2323
*/
2424
namespace Facebook\Tests\GraphNodes;
2525

26-
use Mockery as m;
2726
use Facebook\GraphNodes\GraphNodeFactory;
2827
use Facebook\FacebookResponse;
2928
use PHPUnit\Framework\TestCase;
29+
use Prophecy\Prophecy\ObjectProphecy;
3030

3131
abstract class AbstractGraphNode extends TestCase
3232
{
3333
/**
34-
* @var \Facebook\FacebookResponse|\Mockery\MockInterface
34+
* @var FacebookResponse|ObjectProphecy
3535
*/
3636
protected $responseMock;
3737

3838
protected function setUp()
3939
{
4040
parent::setUp();
41-
$this->responseMock = m::mock(FacebookResponse::class);
41+
42+
$this->responseMock = $this->prophesize(FacebookResponse::class);
4243
}
4344

4445
protected function makeFactoryWithData($data)
4546
{
46-
$this->responseMock
47-
->shouldReceive('getDecodedBody')
48-
->once()
49-
->andReturn($data);
47+
$this->responseMock->getDecodedBody()->willReturn($data);
5048

51-
return new GraphNodeFactory($this->responseMock);
49+
return new GraphNodeFactory($this->responseMock->reveal());
5250
}
5351
}

tests/GraphNodes/GraphAlbumTest.php

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,24 @@
2323
*/
2424
namespace Facebook\Tests\GraphNodes;
2525

26-
use Mockery as m;
2726
use Facebook\GraphNodes\GraphNodeFactory;
2827
use Facebook\GraphNodes\GraphPage;
2928
use Facebook\GraphNodes\GraphUser;
3029
use Facebook\FacebookResponse;
3130
use PHPUnit\Framework\TestCase;
31+
use Prophecy\Prophecy\ObjectProphecy;
3232

3333
class GraphAlbumTest extends TestCase
3434
{
3535

3636
/**
37-
* @var \Facebook\FacebookResponse
37+
* @var FacebookResponse|ObjectProphecy
3838
*/
3939
protected $responseMock;
4040

4141
protected function setUp()
4242
{
43-
$this->responseMock = m::mock(FacebookResponse::class);
43+
$this->responseMock = $this->prophesize(FacebookResponse::class);
4444
}
4545

4646
public function testDatesGetCastToDateTime()
@@ -52,11 +52,8 @@ public function testDatesGetCastToDateTime()
5252
'name' => 'Bar',
5353
];
5454

55-
$this->responseMock
56-
->shouldReceive('getDecodedBody')
57-
->once()
58-
->andReturn($dataFromGraph);
59-
$factory = new GraphNodeFactory($this->responseMock);
55+
$this->responseMock->getDecodedBody()->willReturn($dataFromGraph);
56+
$factory = new GraphNodeFactory($this->responseMock->reveal());
6057
$graphNode = $factory->makeGraphAlbum();
6158

6259
$createdTime = $graphNode->getCreatedTime();
@@ -76,11 +73,8 @@ public function testFromGetsCastAsGraphUser()
7673
],
7774
];
7875

79-
$this->responseMock
80-
->shouldReceive('getDecodedBody')
81-
->once()
82-
->andReturn($dataFromGraph);
83-
$factory = new GraphNodeFactory($this->responseMock);
76+
$this->responseMock->getDecodedBody()->willReturn($dataFromGraph);
77+
$factory = new GraphNodeFactory($this->responseMock->reveal());
8478
$graphNode = $factory->makeGraphAlbum();
8579

8680
$from = $graphNode->getFrom();
@@ -99,11 +93,8 @@ public function testPlacePropertyWillGetCastAsGraphPageObject()
9993
]
10094
];
10195

102-
$this->responseMock
103-
->shouldReceive('getDecodedBody')
104-
->once()
105-
->andReturn($dataFromGraph);
106-
$factory = new GraphNodeFactory($this->responseMock);
96+
$this->responseMock->getDecodedBody()->willReturn($dataFromGraph);
97+
$factory = new GraphNodeFactory($this->responseMock->reveal());
10798
$graphNode = $factory->makeGraphAlbum();
10899

109100
$place = $graphNode->getPlace();

tests/GraphNodes/GraphEventTest.php

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,24 @@
2424
namespace Facebook\Tests\GraphNodes;
2525

2626
use Facebook\FacebookResponse;
27-
use Mockery as m;
2827
use Facebook\GraphNodes\GraphNodeFactory;
2928
use Facebook\GraphNodes\GraphGroup;
3029
use Facebook\GraphNodes\GraphPicture;
3130
use Facebook\GraphNodes\GraphPage;
3231
use Facebook\GraphNodes\GraphCoverPhoto;
3332
use PHPUnit\Framework\TestCase;
33+
use Prophecy\Prophecy\ObjectProphecy;
3434

3535
class GraphEventTest extends TestCase
3636
{
3737
/**
38-
* @var FacebookResponse
38+
* @var FacebookResponse|ObjectProphecy
3939
*/
4040
protected $responseMock;
4141

4242
protected function setUp()
4343
{
44-
$this->responseMock = m::mock(FacebookResponse::class);
44+
$this->responseMock = $this->prophesize(FacebookResponse::class);
4545
}
4646

4747
public function testCoverGetsCastAsGraphCoverPhoto()
@@ -50,11 +50,8 @@ public function testCoverGetsCastAsGraphCoverPhoto()
5050
'cover' => ['id' => '1337']
5151
];
5252

53-
$this->responseMock
54-
->shouldReceive('getDecodedBody')
55-
->once()
56-
->andReturn($dataFromGraph);
57-
$factory = new GraphNodeFactory($this->responseMock);
53+
$this->responseMock->getDecodedBody()->willReturn($dataFromGraph);
54+
$factory = new GraphNodeFactory($this->responseMock->reveal());
5855
$graphObject = $factory->makeGraphEvent();
5956

6057
$cover = $graphObject->getCover();
@@ -67,11 +64,8 @@ public function testPlaceGetsCastAsGraphPage()
6764
'place' => ['id' => '1337']
6865
];
6966

70-
$this->responseMock
71-
->shouldReceive('getDecodedBody')
72-
->once()
73-
->andReturn($dataFromGraph);
74-
$factory = new GraphNodeFactory($this->responseMock);
67+
$this->responseMock->getDecodedBody()->willReturn($dataFromGraph);
68+
$factory = new GraphNodeFactory($this->responseMock->reveal());
7569
$graphObject = $factory->makeGraphEvent();
7670

7771
$place = $graphObject->getPlace();
@@ -84,11 +78,8 @@ public function testPictureGetsCastAsGraphPicture()
8478
'picture' => ['id' => '1337']
8579
];
8680

87-
$this->responseMock
88-
->shouldReceive('getDecodedBody')
89-
->once()
90-
->andReturn($dataFromGraph);
91-
$factory = new GraphNodeFactory($this->responseMock);
81+
$this->responseMock->getDecodedBody()->willReturn($dataFromGraph);
82+
$factory = new GraphNodeFactory($this->responseMock->reveal());
9283
$graphObject = $factory->makeGraphEvent();
9384

9485
$picture = $graphObject->getPicture();
@@ -101,11 +92,8 @@ public function testParentGroupGetsCastAsGraphGroup()
10192
'parent_group' => ['id' => '1337']
10293
];
10394

104-
$this->responseMock
105-
->shouldReceive('getDecodedBody')
106-
->once()
107-
->andReturn($dataFromGraph);
108-
$factory = new GraphNodeFactory($this->responseMock);
95+
$this->responseMock->getDecodedBody()->willReturn($dataFromGraph);
96+
$factory = new GraphNodeFactory($this->responseMock->reveal());
10997
$graphObject = $factory->makeGraphEvent();
11098

11199
$parentGroup = $graphObject->getParentGroup();

tests/GraphNodes/GraphGroupTest.php

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,22 @@
2424
namespace Facebook\Tests\GraphNodes;
2525

2626
use Facebook\FacebookResponse;
27-
use Mockery as m;
2827
use Facebook\GraphNodes\GraphNodeFactory;
2928
use Facebook\GraphNodes\GraphLocation;
3029
use Facebook\GraphNodes\GraphCoverPhoto;
3130
use PHPUnit\Framework\TestCase;
31+
use Prophecy\Prophecy\ObjectProphecy;
3232

3333
class GraphGroupTest extends TestCase
3434
{
3535
/**
36-
* @var FacebookResponse
36+
* @var FacebookResponse|ObjectProphecy
3737
*/
3838
protected $responseMock;
3939

4040
protected function setUp()
4141
{
42-
$this->responseMock = m::mock(FacebookResponse::class);
42+
$this->responseMock = $this->prophesize(FacebookResponse::class);
4343
}
4444

4545
public function testCoverGetsCastAsGraphCoverPhoto()
@@ -48,11 +48,8 @@ public function testCoverGetsCastAsGraphCoverPhoto()
4848
'cover' => ['id' => '1337']
4949
];
5050

51-
$this->responseMock
52-
->shouldReceive('getDecodedBody')
53-
->once()
54-
->andReturn($dataFromGraph);
55-
$factory = new GraphNodeFactory($this->responseMock);
51+
$this->responseMock->getDecodedBody()->willReturn($dataFromGraph);
52+
$factory = new GraphNodeFactory($this->responseMock->reveal());
5653
$graphNode = $factory->makeGraphGroup();
5754

5855
$cover = $graphNode->getCover();
@@ -65,11 +62,8 @@ public function testVenueGetsCastAsGraphLocation()
6562
'venue' => ['id' => '1337']
6663
];
6764

68-
$this->responseMock
69-
->shouldReceive('getDecodedBody')
70-
->once()
71-
->andReturn($dataFromGraph);
72-
$factory = new GraphNodeFactory($this->responseMock);
65+
$this->responseMock->getDecodedBody()->willReturn($dataFromGraph);
66+
$factory = new GraphNodeFactory($this->responseMock->reveal());
7367
$graphNode = $factory->makeGraphGroup();
7468

7569
$venue = $graphNode->getVenue();

tests/GraphNodes/GraphPageTest.php

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,23 @@
2323
*/
2424
namespace Facebook\Tests\GraphNodes;
2525

26-
use Mockery as m;
2726
use Facebook\GraphNodes\GraphNodeFactory;
2827
use Facebook\GraphNodes\GraphLocation;
2928
use Facebook\GraphNodes\GraphPage;
3029
use Facebook\FacebookResponse;
3130
use PHPUnit\Framework\TestCase;
31+
use Prophecy\Prophecy\ObjectProphecy;
3232

3333
class GraphPageTest extends TestCase
3434
{
3535
/**
36-
* @var \Facebook\FacebookResponse
36+
* @var FacebookResponse|ObjectProphecy
3737
*/
3838
protected $responseMock;
3939

4040
protected function setUp()
4141
{
42-
$this->responseMock = m::mock(FacebookResponse::class);
42+
$this->responseMock = $this->prophesize(FacebookResponse::class);
4343
}
4444

4545
public function testPagePropertiesReturnGraphPageObjects()
@@ -57,11 +57,8 @@ public function testPagePropertiesReturnGraphPageObjects()
5757
],
5858
];
5959

60-
$this->responseMock
61-
->shouldReceive('getDecodedBody')
62-
->once()
63-
->andReturn($dataFromGraph);
64-
$factory = new GraphNodeFactory($this->responseMock);
60+
$this->responseMock->getDecodedBody()->willReturn($dataFromGraph);
61+
$factory = new GraphNodeFactory($this->responseMock->reveal());
6562
$graphNode = $factory->makeGraphPage();
6663

6764
$bestPage = $graphNode->getBestPage();
@@ -85,11 +82,8 @@ public function testLocationPropertyWillGetCastAsGraphLocationObject()
8582
],
8683
];
8784

88-
$this->responseMock
89-
->shouldReceive('getDecodedBody')
90-
->once()
91-
->andReturn($dataFromGraph);
92-
$factory = new GraphNodeFactory($this->responseMock);
85+
$this->responseMock->getDecodedBody()->willReturn($dataFromGraph);
86+
$factory = new GraphNodeFactory($this->responseMock->reveal());
9387
$graphNode = $factory->makeGraphPage();
9488

9589
$location = $graphNode->getLocation();

tests/GraphNodes/GraphSessionInfoTest.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,21 @@
2323
*/
2424
namespace Facebook\Tests\GraphNodes;
2525

26-
use Mockery as m;
2726
use Facebook\GraphNodes\GraphNodeFactory;
2827
use Facebook\FacebookResponse;
2928
use PHPUnit\Framework\TestCase;
29+
use Prophecy\Prophecy\ObjectProphecy;
3030

3131
class GraphSessionInfoTest extends TestCase
3232
{
3333
/**
34-
* @var \Facebook\FacebookResponse
34+
* @var FacebookResponse|ObjectProphecy
3535
*/
3636
protected $responseMock;
3737

3838
protected function setUp()
3939
{
40-
$this->responseMock = m::mock(FacebookResponse::class);
40+
$this->responseMock = $this->prophesize(FacebookResponse::class);
4141
}
4242

4343
public function testDatesGetCastToDateTime()
@@ -47,11 +47,8 @@ public function testDatesGetCastToDateTime()
4747
'issued_at' => 1337,
4848
];
4949

50-
$this->responseMock
51-
->shouldReceive('getDecodedBody')
52-
->once()
53-
->andReturn($dataFromGraph);
54-
$factory = new GraphNodeFactory($this->responseMock);
50+
$this->responseMock->getDecodedBody()->willReturn($dataFromGraph);
51+
$factory = new GraphNodeFactory($this->responseMock->reveal());
5552

5653
$graphNode = $factory->makeGraphSessionInfo();
5754

0 commit comments

Comments
 (0)