Skip to content

Commit 22b98e1

Browse files
author
Stephan Wentz
committed
switch to prophecy in tests
1 parent 1665453 commit 22b98e1

7 files changed

Lines changed: 118 additions & 223 deletions

File tree

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
},
1616
"require-dev": {
1717
"mikey179/vfsStream": "~1.2",
18-
"phpunit/phpunit": "~4.5"
18+
"phpunit/phpunit": "~4.5",
19+
"symfony/http-foundation": "~2.3"
1920
},
2021
"autoload": {
2122
"psr-4": { "Brainbits\\Blocking\\": "src/" }

tests/Adapter/FilesystemAdapterTest.php

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@
1212
namespace Brainbits\Blocking\Tests\Adapter;
1313

1414
use Brainbits\Blocking\Adapter\FilesystemAdapter;
15+
use Brainbits\Blocking\Owner\OwnerInterface;
1516
use PHPUnit_Framework_TestCase as TestCase;
1617
use org\bovigo\vfs\vfsStream;
1718
use Brainbits\Blocking\Block;
1819
use Brainbits\Blocking\Identifier\Identifier;
20+
use Prophecy\Prophecy\ObjectProphecy;
1921

2022
/**
2123
* Filesystem adapter test
@@ -34,19 +36,20 @@ class FilesystemAdapterTest extends TestCase
3436
*/
3537
private $root;
3638

39+
/**
40+
* @var OwnerInterface|ObjectProphecy
41+
*/
42+
private $ownerMock;
43+
3744
public function setUp()
3845
{
3946
vfsStream::setup('blockDir');
4047

4148
$this->root = vfsStream::url('blockDir');
4249
$this->adapter = new FilesystemAdapter($this->root);
43-
$this->ownerMock = $this->getMockBuilder('Brainbits\Blocking\Owner\OwnerInterface')
44-
->disableOriginalConstructor()
45-
->getMock();
46-
$this->ownerMock
47-
->expects($this->any())
48-
->method('__toString')
49-
->will($this->returnValue('dummyOwner'));
50+
51+
$this->ownerMock = $this->prophesize(OwnerInterface::class);
52+
$this->ownerMock->__toString()->willReturn('dummyOwner');
5053
}
5154

5255
public function tearDown()
@@ -59,7 +62,7 @@ public function tearDown()
5962
public function testWriteSucceedesOnNewFile()
6063
{
6164
$identifier = new Identifier('test', 'lock');
62-
$block = new Block($identifier, $this->ownerMock, new \DateTime());
65+
$block = new Block($identifier, $this->ownerMock->reveal(), new \DateTime());
6366

6467
$result = $this->adapter->write($block);
6568

@@ -76,7 +79,7 @@ public function testWriteFailsOnNonExistantDirectoryInNonWritableDirectory()
7679
$adapter = new FilesystemAdapter(vfsStream::url('nonWritableDir/blockDir'));
7780

7881
$identifier = new Identifier('test', 'lock');
79-
$block = new Block($identifier, $this->ownerMock, new \DateTime());
82+
$block = new Block($identifier, $this->ownerMock->reveal(), new \DateTime());
8083

8184
$adapter->write($block);
8285
}
@@ -92,7 +95,7 @@ public function testWriteFailsOnNonWritableDirectory()
9295
$adapter = new FilesystemAdapter(vfsStream::url('writableDir/nonWritableBlockDir'));
9396

9497
$identifier = new Identifier('test', 'lock');
95-
$block = new Block($identifier, $this->ownerMock, new \DateTime());
98+
$block = new Block($identifier, $this->ownerMock->reveal(), new \DateTime());
9699

97100
$adapter->write($block);
98101
}
@@ -104,7 +107,7 @@ public function testWriteFailsOnNonWritableDirectory()
104107
public function testTouchSucceedesOnExistingFile()
105108
{
106109
$identifier = new Identifier('test', 'lock');
107-
$block = new Block($identifier, $this->ownerMock, new \DateTime());
110+
$block = new Block($identifier, $this->ownerMock->reveal(), new \DateTime());
108111

109112
$this->adapter->write($block);
110113
$result = $this->adapter->touch($block);
@@ -116,7 +119,7 @@ public function testTouchSucceedesOnExistingFile()
116119
public function testRemoveReturnsFalseOnNonexistingFile()
117120
{
118121
$identifier = new Identifier('test', 'unlock');
119-
$block = new Block($identifier, $this->ownerMock, new \DateTime());
122+
$block = new Block($identifier, $this->ownerMock->reveal(), new \DateTime());
120123

121124
$result = $this->adapter->remove($block);
122125

@@ -127,7 +130,7 @@ public function testRemoveReturnsFalseOnNonexistingFile()
127130
public function testUnblockReturnsTrueOnExistingFile()
128131
{
129132
$identifier = new Identifier('test', 'unlock');
130-
$block = new Block($identifier, $this->ownerMock, new \DateTime());
133+
$block = new Block($identifier, $this->ownerMock->reveal(), new \DateTime());
131134

132135
$this->adapter->write($block);
133136
$result = $this->adapter->remove($block);
@@ -148,7 +151,7 @@ public function testExistsReturnsFalseOnNonexistingFile()
148151
public function testIsBlockedReturnsTrueOnExistingBlock()
149152
{
150153
$identifier = new Identifier('test', 'isblocked');
151-
$block = new Block($identifier, $this->ownerMock, new \DateTime());
154+
$block = new Block($identifier, $this->ownerMock->reveal(), new \DateTime());
152155

153156
$this->adapter->write($block);
154157
$result = $this->adapter->exists($identifier);
@@ -168,7 +171,7 @@ public function testGetReturnsNullOnNonexistingFile()
168171
public function testGetReturnsBlockOnExistingFile()
169172
{
170173
$identifier = new Identifier('test', 'isblocked');
171-
$block = new Block($identifier, $this->ownerMock, new \DateTime());
174+
$block = new Block($identifier, $this->ownerMock->reveal(), new \DateTime());
172175

173176
$this->adapter->write($block);
174177
$result = $this->adapter->get($identifier);

tests/BlockTest.php

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Brainbits\Blocking\Block;
1515
use Brainbits\Blocking\Identifier\IdentifierInterface;
1616
use Brainbits\Blocking\Owner\OwnerInterface;
17+
use DateTime;
1718
use PHPUnit_Framework_TestCase as TestCase;
1819

1920
/**
@@ -35,47 +36,35 @@ class BlockTest extends TestCase
3536

3637
public function setUp()
3738
{
38-
$this->identifierMock = $this->getMockBuilder(IdentifierInterface::class)
39-
->disableOriginalConstructor()
40-
->getMock();
41-
42-
$this->ownerMock = $this->getMockBuilder(OwnerInterface::class)
43-
->disableOriginalConstructor()
44-
->getMock();
45-
$this->ownerMock
46-
->expects($this->any())
47-
->method('__toString')
48-
->will($this->returnValue('dummyOwner'));
49-
}
39+
$this->identifierMock = $this->prophesize(IdentifierInterface::class)->reveal();
5040

51-
public function tearDown()
52-
{
53-
$this->ownerMock = null;
54-
$this->identifier = null;
41+
$ownerMock = $this->prophesize(OwnerInterface::class);
42+
$ownerMock->__toString()->willReturn('dummyOwner');
43+
$this->ownerMock = $ownerMock->reveal();
5544
}
5645

5746
public function testConstruct()
5847
{
59-
$block = new Block($this->identifierMock, $this->ownerMock, new \DateTime());
48+
$block = new Block($this->identifierMock, $this->ownerMock, new DateTime());
6049
}
6150

6251
public function testGetIdentifierReturnsCorrectValue()
6352
{
64-
$block = new Block($this->identifierMock, $this->ownerMock, new \DateTime());
53+
$block = new Block($this->identifierMock, $this->ownerMock, new DateTime());
6554

6655
$this->assertSame($this->identifierMock, $block->getIdentifier());
6756
}
6857

6958
public function testGetOwnerReturnsCorrectValue()
7059
{
71-
$block = new Block($this->identifierMock, $this->ownerMock, new \DateTime());
60+
$block = new Block($this->identifierMock, $this->ownerMock, new DateTime());
7261

7362
$this->assertSame($this->ownerMock, $block->getOwner());
7463
}
7564

7665
public function testGetCreatedAtReturnsCorrectValue()
7766
{
78-
$createdAt = new \DateTime();
67+
$createdAt = new DateTime();
7968

8069
$block = new Block($this->identifierMock, $this->ownerMock, $createdAt);
8170
$result = $block->getCreatedAt();
@@ -86,7 +75,7 @@ public function testGetCreatedAtReturnsCorrectValue()
8675

8776
public function testGetUpdatedAtReturnsCreatedAtValueAfterInstanciation()
8877
{
89-
$createdAt = new \DateTime();
78+
$createdAt = new DateTime();
9079

9180
$block = new Block($this->identifierMock, $this->ownerMock, $createdAt);
9281
$result = $block->getUpdatedAt();
@@ -97,11 +86,11 @@ public function testGetUpdatedAtReturnsCreatedAtValueAfterInstanciation()
9786

9887
public function testSetUpdatedAtUpdatesValue()
9988
{
100-
$createdAt = new \DateTime();
89+
$createdAt = new DateTime();
10190

10291
$block = new Block($this->identifierMock, $this->ownerMock, $createdAt);
10392

104-
$updatedAt = new \DateTime();
93+
$updatedAt = new DateTime();
10594
$block->setUpdatedAt($updatedAt);
10695
$result = $block->getUpdatedAt();
10796

0 commit comments

Comments
 (0)