Skip to content

Commit

Permalink
Use createMock instead of getMock to mock an object
Browse files Browse the repository at this point in the history
And drop old PHP versions that don't support the new mock method
  • Loading branch information
WyriHaximus committed Apr 26, 2020
1 parent f186687 commit f2a4dfd
Show file tree
Hide file tree
Showing 13 changed files with 58 additions and 60 deletions.
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ cache:
- $HOME/.composer/cache/files

php:
- 5.4
- 5.5
- 5.6
- 7.0
- 7.1
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
}
],
"require": {
"php": ">=5.4.0",
"php": ">=5.6.0",
"evenement/evenement": "^3.0 || ^2.0",
"react/event-loop": "^1.0 || ^0.5 || ^0.4",
"react/promise": "~2.2",
Expand All @@ -20,7 +20,7 @@
},
"require-dev": {
"clue/block-react": "^1.1",
"phpunit/phpunit": "^7.0 || ^6.0 || ^5.0 || ^4.8"
"phpunit/phpunit": "^7.0 || ^6.0 || ^5.0"
},
"autoload": {
"psr-4": {
Expand All @@ -36,7 +36,7 @@
"config": {
"sort-packages": true,
"platform": {
"php": "5.4"
"php": "5.6"
}
}
}
10 changes: 5 additions & 5 deletions tests/ChildProcess/AdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function testInterface()
{
$this->assertInstanceOf(
'React\Filesystem\AdapterInterface',
new Adapter($this->getMock('React\EventLoop\LoopInterface'), [
new Adapter($this->createMock('React\EventLoop\LoopInterface'), [
'pool' => [
'class' => 'WyriHaximus\React\ChildProcess\Pool\Pool\Dummy',
],
Expand All @@ -32,7 +32,7 @@ public function testInterface()

public function testGetLoop()
{
$loop = $this->getMock('React\EventLoop\LoopInterface');
$loop = $this->createMock('React\EventLoop\LoopInterface');
$filesystem = new Adapter($loop, [
'pool' => [
'class' => 'WyriHaximus\React\ChildProcess\Pool\Pool\Dummy',
Expand All @@ -43,7 +43,7 @@ public function testGetLoop()

public function testGetSetFilesystem()
{
$loop = $this->getMock('React\EventLoop\LoopInterface');
$loop = $this->createMock('React\EventLoop\LoopInterface');
$filesystem = new Adapter($loop, [
'pool' => [
'class' => 'WyriHaximus\React\ChildProcess\Pool\Pool\Dummy',
Expand Down Expand Up @@ -214,7 +214,7 @@ public function callFilesystemProvider()
*/
public function testCallFilesystem($method, $arguments, $mockArguments)
{
$loop = $this->getMock('React\EventLoop\LoopInterface');
$loop = $this->createMock('React\EventLoop\LoopInterface');
$filesystem = new Adapter($loop, [
'pool' => [
'class' => 'React\Tests\Filesystem\ChildProcess\SingletonPoolStub',
Expand Down Expand Up @@ -271,7 +271,7 @@ public function testLs()

public function testLsStream()
{
$loop = $this->getMock('React\EventLoop\LoopInterface');
$loop = $this->createMock('React\EventLoop\LoopInterface');
$adapter = new Adapter($loop, [
'pool' => [
'class' => 'React\Tests\Filesystem\ChildProcess\SingletonPoolStub',
Expand Down
6 changes: 3 additions & 3 deletions tests/FilesystemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public function testCreate()
{
$this->assertInstanceOf(
'React\Filesystem\Filesystem',
Filesystem::create($this->getMock('React\EventLoop\LoopInterface'), [
Filesystem::create($this->createMock('React\EventLoop\LoopInterface'), [
'pool' => [
'class' => 'WyriHaximus\React\ChildProcess\Pool\Pool\Dummy',
],
Expand Down Expand Up @@ -44,7 +44,7 @@ public function testFactory()

public function testFile()
{
$file = Filesystem::create($this->getMock('React\EventLoop\LoopInterface'), [
$file = Filesystem::create($this->createMock('React\EventLoop\LoopInterface'), [
'pool' => [
'class' => 'WyriHaximus\React\ChildProcess\Pool\Pool\Dummy',
],
Expand All @@ -55,7 +55,7 @@ public function testFile()

public function testDir()
{
$directory = Filesystem::create($this->getMock('React\EventLoop\LoopInterface'), [
$directory = Filesystem::create($this->createMock('React\EventLoop\LoopInterface'), [
'pool' => [
'class' => 'WyriHaximus\React\ChildProcess\Pool\Pool\Dummy',
],
Expand Down
2 changes: 1 addition & 1 deletion tests/FlagResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class FlagResolverTest extends TestCase

public function testResolve()
{
$resolver = $this->getMock('React\Filesystem\FlagResolver', [
$resolver = $this->createMock('React\Filesystem\FlagResolver', [
'defaultFlags',
'flagMapping',
]);
Expand Down
42 changes: 21 additions & 21 deletions tests/Node/DirectoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function testGetPath()
public function testLs()
{
$path = '/home/foo/bar';
$loop = $this->getMock('React\EventLoop\LoopInterface');
$loop = $this->createMock('React\EventLoop\LoopInterface');

$filesystem = $this->mockAdapter($loop);

Expand All @@ -62,11 +62,11 @@ public function testLs()
public function testLsStream()
{
$path = '/home/foo/bar';
$loop = $this->getMock('React\EventLoop\LoopInterface');
$loop = $this->createMock('React\EventLoop\LoopInterface');

$filesystem = $this->mockAdapter($loop);

$lsStream = $this->getMock('React\Filesystem\ObjectStream');
$lsStream = $this->createMock('React\Filesystem\ObjectStream');

$filesystem
->expects($this->once())
Expand Down Expand Up @@ -125,7 +125,7 @@ public function testRemove()
{
$path = 'foo.bar';
$filesystem = $this->mockAdapter();
$promise = $this->getMock('React\Promise\PromiseInterface');
$promise = $this->createMock('React\Promise\PromiseInterface');

$filesystem
->expects($this->once())
Expand All @@ -139,11 +139,11 @@ public function testRemove()
public function testSize()
{
$path = '/home/foo/bar';
$loop = $this->getMock('React\EventLoop\LoopInterface');
$loop = $this->createMock('React\EventLoop\LoopInterface');

$filesystem = $this->mockAdapter($loop);

$lsPromise = $this->getMock('React\Promise\PromiseInterface', [
$lsPromise = $this->createMock('React\Promise\PromiseInterface', [
'then',
]);

Expand All @@ -156,7 +156,7 @@ public function testSize()
}))
;

$directory = $this->getMock('React\Filesystem\Node\Directory', [
$directory = $this->createMock('React\Filesystem\Node\Directory', [
'ls',
'processSizeContents',
], [
Expand All @@ -175,7 +175,7 @@ public function testSize()
->expects($this->once())
->method('processSizeContents')
->with('foo.bar', $this->isType('boolean'))
->will($this->returnValue($this->getMock('React\Promise\PromiseInterface')))
->will($this->returnValue($this->createMock('React\Promise\PromiseInterface')))
;

$this->assertInstanceOf('React\Promise\PromiseInterface', $directory->size());
Expand All @@ -185,16 +185,16 @@ public function testChmodRecursive()
{
$filesystem = $this->mockAdapter();

$recursiveInvoker = $this->getMock('React\Filesystem\Node\RecursiveInvoker', [
$recursiveInvoker = $this->createMock('React\Filesystem\Node\RecursiveInvoker', [
'execute',
], [
$this->getMock('React\Filesystem\Node\DirectoryInterface', [], [
$this->createMock('React\Filesystem\Node\DirectoryInterface', [], [
'foo/bar/',
Filesystem::createFromAdapter($filesystem),
]),
]);

$promise = $this->getMock('React\Promise\PromiseInterface');
$promise = $this->createMock('React\Promise\PromiseInterface');

$recursiveInvoker
->expects($this->once())
Expand All @@ -210,16 +210,16 @@ public function testChownRecursive()
{
$filesystem = $this->mockAdapter();

$recursiveInvoker = $this->getMock('React\Filesystem\Node\RecursiveInvoker', [
$recursiveInvoker = $this->createMock('React\Filesystem\Node\RecursiveInvoker', [
'execute',
], [
$this->getMock('React\Filesystem\Node\DirectoryInterface', [], [
$this->createMock('React\Filesystem\Node\DirectoryInterface', [], [
'foo/bar/',
Filesystem::createFromAdapter($filesystem),
]),
]);

$promise = $this->getMock('React\Promise\PromiseInterface');
$promise = $this->createMock('React\Promise\PromiseInterface');

$recursiveInvoker
->expects($this->once())
Expand All @@ -235,16 +235,16 @@ public function testRemoveRecursive()
{
$filesystem = $this->mockAdapter();

$recursiveInvoker = $this->getMock('React\Filesystem\Node\RecursiveInvoker', [
$recursiveInvoker = $this->createMock('React\Filesystem\Node\RecursiveInvoker', [
'execute',
], [
$this->getMock('React\Filesystem\Node\DirectoryInterface', [], [
$this->createMock('React\Filesystem\Node\DirectoryInterface', [], [
'foo/bar/',
Filesystem::createFromAdapter($filesystem),
]),
]);

$promise = $this->getMock('React\Promise\PromiseInterface');
$promise = $this->createMock('React\Promise\PromiseInterface');

$recursiveInvoker
->expects($this->once())
Expand All @@ -260,7 +260,7 @@ public function testCopy()
{
$filesystem = $this->mockAdapter();

$directoryFrom = $this->getMock('React\Filesystem\Node\Directory', [
$directoryFrom = $this->createMock('React\Filesystem\Node\Directory', [
'copyStreaming',
], [
'foo.bar',
Expand Down Expand Up @@ -338,7 +338,7 @@ public function testCopyStreamingABC()
->will($this->returnValue(new FulfilledPromise()))
;

$directoryFrom = $this->getMock('React\Filesystem\Node\Directory', [
$directoryFrom = $this->createMock('React\Filesystem\Node\Directory', [
'lsStreaming',
], [
'foo.bar',
Expand All @@ -358,7 +358,7 @@ public function testCopyStreamingABC()
$returnedStream = $directoryFrom->copyStreaming($directoryTo);
$this->assertInstanceOf('React\Filesystem\ObjectStream', $returnedStream);

$file = $this->getMock('React\Filesystem\Node\File', [
$file = $this->createMock('React\Filesystem\Node\File', [
'copyStreaming',
], [
'foo.bar',
Expand All @@ -378,7 +378,7 @@ public function testCopyStreamingABC()
$file,
]);

$directory = $this->getMock('React\Filesystem\Node\Directory', [
$directory = $this->createMock('React\Filesystem\Node\Directory', [
'copyStreaming',
], [
'foo.bar',
Expand Down
12 changes: 6 additions & 6 deletions tests/Node/FileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function testRemove()
{
$path = 'foo.bar';
$filesystem = $this->mockAdapter();
$promise = $this->getMock('React\Promise\PromiseInterface');
$promise = $this->createMock('React\Promise\PromiseInterface');

$filesystem
->expects($this->once())
Expand Down Expand Up @@ -78,7 +78,7 @@ public function testExists()
$path = 'foo.bar';
$filesystem = $this->mockAdapter();

$file = $this->getMock('React\Filesystem\Node\File', [
$file = $this->createMock('React\Filesystem\Node\File', [
'stat',
], [
$path,
Expand All @@ -102,7 +102,7 @@ public function testDoesntExists()
$path = 'foo.bar';
$filesystem = $this->mockAdapter();

$file = $this->getMock('React\Filesystem\Node\File', [
$file = $this->createMock('React\Filesystem\Node\File', [
'stat',
], [
$path,
Expand Down Expand Up @@ -348,7 +348,7 @@ public function testTouch()
->expects($this->once())
->method('touch')
->with($path)
->will($this->returnValue($this->getMock('React\Promise\PromiseInterface')))
->will($this->returnValue($this->createMock('React\Promise\PromiseInterface')))
;

$this->assertInstanceOf('React\Promise\PromiseInterface', (new File($path, Filesystem::createFromAdapter($filesystem)))->touch());
Expand All @@ -358,7 +358,7 @@ public function testCopy()
{
$filesystem = $this->mockAdapter();

$fileFrom = $this->getMock('React\Filesystem\Node\File', [
$fileFrom = $this->createMock('React\Filesystem\Node\File', [
'copyStreaming',
], [
'foo.bar',
Expand Down Expand Up @@ -392,7 +392,7 @@ public function testCopyDirectory()
{
$filesystem = $this->mockAdapter();

$file = $this->getMock('React\Filesystem\Node\File', [
$file = $this->createMock('React\Filesystem\Node\File', [
'copyToFile',
], [
'foo.bar',
Expand Down
10 changes: 5 additions & 5 deletions tests/Node/RecursiveInvokerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ public function testExecute()
{
$filesystem = $this->mockAdapter();

$node = $this->getMock('React\Filesystem\Node\Directory', [
$node = $this->createMock('React\Filesystem\Node\Directory', [
'ls',
'chmod',
], [
'foo.bar',
Filesystem::createFromAdapter($filesystem),
]);

$promise = $this->getMock('React\Promise\PromiseInterface');
$promise = $this->createMock('React\Promise\PromiseInterface');

$node
->expects($this->once())
Expand All @@ -31,7 +31,7 @@ public function testExecute()
->will($this->returnValue($promise))
;

$fileDent = $this->getMock('React\Filesystem\Node\File', [
$fileDent = $this->createMock('React\Filesystem\Node\File', [
'chmod',
], [
'foo',
Expand All @@ -45,7 +45,7 @@ public function testExecute()
->will($this->returnValue(new FulfilledPromise()))
;

$directoryDent = $this->getMock('React\Filesystem\Node\Directory', [
$directoryDent = $this->createMock('React\Filesystem\Node\Directory', [
'chmodRecursive',
], [
'foo',
Expand All @@ -59,7 +59,7 @@ public function testExecute()
->will($this->returnValue(new FulfilledPromise()))
;

$finalPromise = $this->getMock('React\Promise\PromiseInterface');
$finalPromise = $this->createMock('React\Promise\PromiseInterface');

$node
->expects($this->once())
Expand Down
2 changes: 1 addition & 1 deletion tests/ObjectStreamSinkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class ObjectStreamSinkTest extends TestCase
{
public function testSink()
{
$node = $this->getMock('React\Filesystem\Node\NodeInterface');
$node = $this->createMock('React\Filesystem\Node\NodeInterface');
$stream = new ObjectStream();
$sink = ObjectStreamSink::promise($stream);
$this->assertInstanceOf('React\Promise\PromiseInterface', $sink);
Expand Down
2 changes: 1 addition & 1 deletion tests/ObjectStreamTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class ObjectStreamTest extends TestCase
{
public function testObjectStream()
{
$node = $this->getMock('React\Filesystem\Node\NodeInterface');
$node = $this->createMock('React\Filesystem\Node\NodeInterface');
$stream = new ObjectStream();

$this->assertTrue($stream->isWritable());
Expand Down
Loading

0 comments on commit f2a4dfd

Please sign in to comment.