Permalink
Browse files

replace usage of phpunit/phpunit-mock-objects with bovigo/callmap

To be more precise all methods of the org\bovigo\vfs\visitor\vfsStreamVisitor
interface have been changed to explicitly return itself. This is both
helpful for where this interface is used as well as for bovigo/callmap as it
can infer that the instance must return itself automatically.

 - bovigo/callmap installed in version v4.0.0
   Release notes: https://github.com/mikey179/bovigo-callmap/releases/tag/v4.0.0
  • Loading branch information...
mikey179 committed Sep 21, 2017
1 parent fa8f35d commit 0b04b768551b41cd44d7e2bde3886ac03ea8d3e9
View
@@ -4,6 +4,7 @@
### BC breaks
* raised minimum required PHP version to 7.1.0
* all methods of `org\bovigo\vfs\visitor\vfsStreamVisitor` are now declared with `self` as return type
1.6.5 (2017-08-01)
View
@@ -20,7 +20,8 @@
"php": "^7.1"
},
"require-dev": {
"phpunit/phpunit": "^6.3"
"phpunit/phpunit": "^6.3",
"bovigo/callmap": "^4.0"
},
"autoload": {
"psr-0": { "org\\bovigo\\vfs\\": "src/main/php" }
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -26,7 +26,7 @@
* @return vfsStreamVisitor
* @throws \InvalidArgumentException
*/
public function visit(vfsStreamContent $content)
public function visit(vfsStreamContent $content): vfsStreamVisitor
{
switch ($content->getType()) {
case vfsStreamContent::TYPE_BLOCK:
@@ -57,7 +57,7 @@ public function visit(vfsStreamContent $content)
* @param vfsStreamBlock $block
* @return vfsStreamVisitor
*/
public function visitBlockDevice(vfsStreamBlock $block)
public function visitBlockDevice(vfsStreamBlock $block): vfsStreamVisitor
{
return $this->visitFile($block);
}
@@ -58,7 +58,7 @@ public function __construct($out = STDOUT)
* @param vfsStreamFile $file
* @return vfsStreamPrintVisitor
*/
public function visitFile(vfsStreamFile $file)
public function visitFile(vfsStreamFile $file): vfsStreamVisitor
{
$this->printContent($file->getName());
return $this;
@@ -70,7 +70,7 @@ public function visitFile(vfsStreamFile $file)
* @param vfsStreamBlock $block
* @return vfsStreamPrintVisitor
*/
public function visitBlockDevice(vfsStreamBlock $block)
public function visitBlockDevice(vfsStreamBlock $block): vfsStreamVisitor
{
$name = '[' . $block->getName() . ']';
$this->printContent($name);
@@ -83,7 +83,7 @@ public function visitBlockDevice(vfsStreamBlock $block)
* @param vfsStreamDirectory $dir
* @return vfsStreamPrintVisitor
*/
public function visitDirectory(vfsStreamDirectory $dir)
public function visitDirectory(vfsStreamDirectory $dir): vfsStreamVisitor
{
$this->printContent($dir->getName());
$this->depth++;
@@ -49,7 +49,7 @@ public function __construct()
* @param vfsStreamFile $file
* @return vfsStreamStructureVisitor
*/
public function visitFile(vfsStreamFile $file)
public function visitFile(vfsStreamFile $file): vfsStreamVisitor
{
$this->current[$file->getName()] = $file->getContent();
return $this;
@@ -61,7 +61,7 @@ public function visitFile(vfsStreamFile $file)
* @param vfsStreamBlock $block
* @return vfsStreamStructureVisitor
*/
public function visitBlockDevice(vfsStreamBlock $block)
public function visitBlockDevice(vfsStreamBlock $block): vfsStreamVisitor
{
$this->current['[' . $block->getName() . ']'] = $block->getContent();
return $this;
@@ -73,7 +73,7 @@ public function visitBlockDevice(vfsStreamBlock $block)
* @param vfsStreamDirectory $dir
* @return vfsStreamStructureVisitor
*/
public function visitDirectory(vfsStreamDirectory $dir)
public function visitDirectory(vfsStreamDirectory $dir): vfsStreamVisitor
{
$this->current[$dir->getName()] = array();
$tmp =& $this->current;
@@ -92,7 +92,7 @@ public function visitDirectory(vfsStreamDirectory $dir)
* @return array
* @api
*/
public function getStructure()
public function getStructure(): array
{
return $this->structure;
}
@@ -102,7 +102,7 @@ public function getStructure()
*
* @return vfsStreamStructureVisitor
*/
public function reset()
public function reset(): self
{
$this->structure = array();
$this->current =& $this->structure;
@@ -27,29 +27,29 @@
* @param vfsStreamContent $content
* @return vfsStreamVisitor
*/
public function visit(vfsStreamContent $content);
public function visit(vfsStreamContent $content): self;
/**
* visit a file and process it
*
* @param vfsStreamFile $file
* @return vfsStreamVisitor
*/
public function visitFile(vfsStreamFile $file);
public function visitFile(vfsStreamFile $file): self;
/**
* visit a directory and process it
*
* @param vfsStreamDirectory $dir
* @return vfsStreamVisitor
*/
public function visitDirectory(vfsStreamDirectory $dir);
public function visitDirectory(vfsStreamDirectory $dir): self;
/**
* visit a block device and process it
*
* @param vfsStreamBlock $block
* @return vfsStreamVisitor
*/
public function visitBlockDevice(vfsStreamBlock $block);
public function visitBlockDevice(vfsStreamBlock $block): self;
}
@@ -8,6 +8,7 @@
* @package org\bovigo\vfs
*/
namespace org\bovigo\vfs;
use bovigo\callmap\NewInstance;
use PHPUnit\Framework\TestCase;
/**
* Test for org\bovigo\vfs\vfsStreamContainerIterator.
@@ -23,32 +24,31 @@ class vfsStreamContainerIteratorTestCase extends TestCase
/**
* child one
*
* @type \PHPUnit_Framework_MockObject_MockObject
* @type vfsStreamContent
*/
private $mockChild1;
private $child1;
/**
* child two
*
* @type \PHPUnit_Framework_MockObject_MockObject
* @type vfsStreamContent
*/
private $mockChild2;
private $child2;
/**
* set up test environment
*/
public function setUp()
{
$this->dir = new vfsStreamDirectory('foo');
$this->mockChild1 = $this->createMock('org\\bovigo\\vfs\\vfsStreamContent');
$this->mockChild1->expects($this->any())
->method('getName')
->will($this->returnValue('bar'));
$this->dir->addChild($this->mockChild1);
$this->mockChild2 = $this->createMock('org\\bovigo\\vfs\\vfsStreamContent');
$this->mockChild2->expects($this->any())
->method('getName')
->will($this->returnValue('baz'));
$this->dir->addChild($this->mockChild2);
$this->child1 = NewInstance::of(vfsStreamContent::class)->returns([
'getName' => 'bar'
]);
$this->dir->addChild($this->child1);
$this->child2 = NewInstance::of(vfsStreamContent::class)->returns([
'getName' => 'baz'
]);
$this->dir->addChild($this->child2);
}
/**
@@ -59,41 +59,34 @@ public function tearDown()
vfsStream::enableDotfiles();
}
/**
* @return array
*/
public function provideSwitchWithExpectations()
public function provideSwitchWithExpectations(): array
{
return array(array(function() { vfsStream::disableDotfiles(); },
array()
),
array(function() { vfsStream::enableDotfiles(); },
array('.', '..')
)
);
return [
[[vfsStream::class, 'disableDotfiles'], []],
[[vfsStream::class, 'enableDotfiles'], ['.', '..']]
];
}
private function getDirName($dir)
private function getDirName($dir): string
{
if (is_string($dir)) {
return $dir;
}
return $dir->getName();
}
/**
* @param \Closure $dotFilesSwitch
* @param callable $switchDotFiles
* @param array $dirNames
* @test
* @dataProvider provideSwitchWithExpectations
*/
public function iteration(\Closure $dotFilesSwitch, array $dirs)
public function iteration(callable $switchDotFiles, array $dirs)
{
$dirs[] = $this->mockChild1;
$dirs[] = $this->mockChild2;
$dotFilesSwitch();
$dirs[] = $this->child1;
$dirs[] = $this->child2;
$switchDotFiles();
$dirIterator = $this->dir->getIterator();
foreach ($dirs as $dir) {
$this->assertEquals($this->getDirName($dir), $dirIterator->key());
Oops, something went wrong.

0 comments on commit 0b04b76

Please sign in to comment.