Skip to content

Commit

Permalink
Merge pull request #310 from garak/csfix
Browse files Browse the repository at this point in the history
cs fix on tests
  • Loading branch information
garak committed Sep 2, 2019
2 parents 13e3e32 + 04b075d commit 2d54f8e
Show file tree
Hide file tree
Showing 27 changed files with 245 additions and 263 deletions.
64 changes: 32 additions & 32 deletions tests/Knp/Menu/Tests/Factory/CoreExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,82 +7,82 @@
use Knp\Menu\MenuItem;
use PHPUnit\Framework\TestCase;

class CoreExtensionTest extends TestCase
final class CoreExtensionTest extends TestCase
{
public function testBuildOptions(): void
{
$extension = $this->getExtension();
$item = $this->createItem( 'test' );

$options = $extension->buildOptions( [] );

$this->assertArrayHasKey( 'uri', $options );
$this->assertArrayHasKey( 'label', $options );
$this->assertArrayHasKey( 'attributes', $options );
$this->assertArrayHasKey( 'linkAttributes', $options );
$this->assertArrayHasKey( 'childrenAttributes', $options );
$this->assertArrayHasKey( 'labelAttributes', $options );
$this->assertArrayHasKey( 'extras', $options );
$this->assertArrayHasKey( 'current', $options );
$this->assertArrayHasKey( 'display', $options );
$this->assertArrayHasKey( 'displayChildren', $options );
$item = $this->createItem('test');

$options = $extension->buildOptions([]);

$this->assertArrayHasKey('uri', $options);
$this->assertArrayHasKey('label', $options);
$this->assertArrayHasKey('attributes', $options);
$this->assertArrayHasKey('linkAttributes', $options);
$this->assertArrayHasKey('childrenAttributes', $options);
$this->assertArrayHasKey('labelAttributes', $options);
$this->assertArrayHasKey('extras', $options);
$this->assertArrayHasKey('current', $options);
$this->assertArrayHasKey('display', $options);
$this->assertArrayHasKey('displayChildren', $options);
}

public function testBuildItemsSetsExtras(): void
{
$item = $this->createItem( 'test' );
$item->setExtra( 'test1', 'original value' );
$item = $this->createItem('test');
$item->setExtra('test1', 'original value');
$extension = $this->getExtension();
$options = $extension->buildOptions(
[
'extras' => [
'test1' => 'options value 1',
'test2' => 'options value 2',
]
],
]
);

$extension->buildItem( $item, $options );
$extension->buildItem($item, $options);

$extras = $item->getExtras();

$this->assertEquals( 2, count( $extras ) );
$this->assertCount(2, $extras);

$this->assertArrayHasKey( 'test1', $extras );
$this->assertEquals( 'options value 1', $item->getExtra( 'test1' ) );
$this->assertArrayHasKey('test1', $extras);
$this->assertEquals('options value 1', $item->getExtra('test1'));

$this->assertArrayHasKey( 'test2', $extras );
$this->assertEquals( 'options value 2', $item->getExtra( 'test2' ) );
$this->assertArrayHasKey('test2', $extras);
$this->assertEquals('options value 2', $item->getExtra('test2'));
}

public function testBuildItemDoesNotOverrideExistingExtras(): void
{
$item = $this->createItem( 'test' );
$item->setExtra( 'test1', 'original value' );
$item = $this->createItem('test');
$item->setExtra('test1', 'original value');
$extension = $this->getExtension();
$options = $extension->buildOptions(
[
'extras' => [
'test2' => 'options value',
]
],
]
);

$extension->buildItem( $item, $options );
$extension->buildItem($item, $options);

$this->assertArrayHasKey( 'test1', $item->getExtras() );
$this->assertEquals( 'original value', $item->getExtra( 'test1' ) );
$this->assertArrayHasKey('test1', $item->getExtras());
$this->assertEquals('original value', $item->getExtra('test1'));
}

private function getExtension()
{
return new CoreExtension();
}

private function createItem( $name )
private function createItem($name)
{
$factory = new MenuFactory();
$item = new MenuItem( $name, $factory );
$item = new MenuItem($name, $factory);

return $item;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
use PHPUnit\Framework\TestCase;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;

class RoutingExtensionTest extends TestCase
final class RoutingExtensionTest extends TestCase
{
protected function setUp(): void
{
if (!interface_exists('Symfony\Component\Routing\Generator\UrlGeneratorInterface')) {
if (!\interface_exists('Symfony\Component\Routing\Generator\UrlGeneratorInterface')) {
$this->markTestSkipped('The Symfony Routing component is not available');
}
}
Expand All @@ -21,7 +21,7 @@ public function testCreateItemWithRoute(): void
$generator->expects($this->once())
->method('generate')
->with('homepage', [], UrlGeneratorInterface::ABSOLUTE_PATH)
->will($this->returnValue('/foobar'))
->willReturn('/foobar')
;

$extension = new RoutingExtension($generator);
Expand All @@ -38,7 +38,7 @@ public function testCreateItemWithRouteAndParameters(): void
$generator->expects($this->once())
->method('generate')
->with('homepage', ['id' => 12], UrlGeneratorInterface::ABSOLUTE_PATH)
->will($this->returnValue('/foobar'))
->willReturn('/foobar')
;

$extension = new RoutingExtension($generator);
Expand All @@ -54,7 +54,7 @@ public function testCreateItemWithAbsoluteRoute(): void
$generator->expects($this->once())
->method('generate')
->with('homepage', [], UrlGeneratorInterface::ABSOLUTE_URL)
->will($this->returnValue('http://php.net'))
->willReturn('http://php.net')
;

$extension = new RoutingExtension($generator);
Expand All @@ -70,13 +70,13 @@ public function testCreateItemAppendsRouteUnderExtras(): void

$extension = new RoutingExtension($generator);

$processedOptions = $extension->buildOptions( ['route' => 'homepage']);
$processedOptions = $extension->buildOptions(['route' => 'homepage']);
$this->assertEquals([['route' => 'homepage', 'parameters' => []]], $processedOptions['extras']['routes']);

$processedOptions = $extension->buildOptions( ['route' => 'homepage', 'routeParameters' => ['bar' => 'baz']]);
$processedOptions = $extension->buildOptions(['route' => 'homepage', 'routeParameters' => ['bar' => 'baz']]);
$this->assertEquals([['route' => 'homepage', 'parameters' => ['bar' => 'baz']]], $processedOptions['extras']['routes']);

$processedOptions = $extension->buildOptions( ['route' => 'homepage', 'extras' => ['routes' => ['other_page']]]);
$processedOptions = $extension->buildOptions(['route' => 'homepage', 'extras' => ['routes' => ['other_page']]]);
$this->assertContains(['route' => 'homepage', 'parameters' => []], $processedOptions['extras']['routes']);
$this->assertContains('other_page', $processedOptions['extras']['routes']);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Knp\Menu\Matcher\Matcher;
use Knp\Menu\Tests\MenuTestCase;

class CurrentItemFilterIteratorTest extends MenuTestCase
final class CurrentItemFilterIteratorTest extends MenuTestCase
{
public function testSimpleFiltering(): void
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Knp\Menu\Iterator\RecursiveItemIterator;
use Knp\Menu\Tests\MenuTestCase;

class DisplayedItemFilterIteratorTest extends MenuTestCase
final class DisplayedItemFilterIteratorTest extends MenuTestCase
{
public function testFiltering(): void
{
Expand Down
8 changes: 4 additions & 4 deletions tests/Knp/Menu/Tests/Iterator/IteratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
use Knp\Menu\Iterator\RecursiveItemIterator;
use Knp\Menu\Tests\MenuTestCase;

class IteratorTest extends MenuTestCase
final class IteratorTest extends MenuTestCase
{
public function testIterator(): void
{
$count = 0;
foreach ($this->pt1 as $key => $value) {
$count++;
++$count;
$this->assertEquals('Child '.$count, $key);
$this->assertEquals('Child '.$count, $value->getLabel());
}
Expand All @@ -23,10 +23,10 @@ public function testRecursiveIterator(): void
$child = $this->getMockBuilder('Knp\Menu\ItemInterface')->getMock();
$child->expects($this->any())
->method('getName')
->will($this->returnValue('Foo'));
->willReturn('Foo');
$child->expects($this->any())
->method('getIterator')
->will($this->returnValue(new \EmptyIterator()));
->willReturn(new \EmptyIterator());
$this->menu->addChild($child);

$names = [];
Expand Down
17 changes: 8 additions & 9 deletions tests/Knp/Menu/Tests/Loader/ArrayLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Knp\Menu\MenuFactory;
use PHPUnit\Framework\TestCase;

class ArrayLoaderTest extends TestCase
final class ArrayLoaderTest extends TestCase
{
public function testLoadWithoutChildren(): void
{
Expand Down Expand Up @@ -36,8 +36,8 @@ public function testLoadWithChildren(): void
'label' => 'Jack',
],
[
'name' => 'john'
]
'name' => 'john',
],
],
];

Expand All @@ -59,8 +59,8 @@ public function testLoadWithChildrenOmittingName(): void
'label' => 'Jack',
],
'john' => [
'label' => 'John'
]
'label' => 'John',
],
],
];

Expand All @@ -74,11 +74,10 @@ public function testLoadWithChildrenOmittingName(): void
$this->assertTrue(isset($item['jack']));
}

/**
* @expectedException \InvalidArgumentException
*/
public function testLoadInvalidData()
public function testLoadInvalidData(): void
{
$this->expectException(\InvalidArgumentException::class);

$loader = new ArrayLoader(new MenuFactory());

$loader->load(new \stdClass());
Expand Down
14 changes: 7 additions & 7 deletions tests/Knp/Menu/Tests/Matcher/MatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Knp\Menu\Matcher\Matcher;
use PHPUnit\Framework\TestCase;

class MatcherTest extends TestCase
final class MatcherTest extends TestCase
{
/**
* @param bool|null $flag
Expand All @@ -18,7 +18,7 @@ public function testItemFlag($flag, $expected): void
$item = $this->getMockBuilder('Knp\Menu\ItemInterface')->getMock();
$item->expects($this->any())
->method('isCurrent')
->will($this->returnValue($flag));
->willReturn($flag);

$matcher = new Matcher();

Expand Down Expand Up @@ -57,7 +57,7 @@ public function testFlagWinsOverVoter($value): void
$item = $this->getMockBuilder('Knp\Menu\ItemInterface')->getMock();
$item->expects($this->any())
->method('isCurrent')
->will($this->returnValue($value));
->willReturn($value);

$voter = $this->getMockBuilder('Knp\Menu\Matcher\Voter\VoterInterface')->getMock();
$voter->expects($this->never())
Expand All @@ -78,13 +78,13 @@ public function testFirstVoterWins($value): void
$item = $this->getMockBuilder('Knp\Menu\ItemInterface')->getMock();
$item->expects($this->any())
->method('isCurrent')
->will($this->returnValue(null));
->willReturn(null);

$voter1 = $this->getMockBuilder('Knp\Menu\Matcher\Voter\VoterInterface')->getMock();
$voter1->expects($this->once())
->method('matchItem')
->with($this->equalTo($item))
->will($this->returnValue($value));
->willReturn($value);

$voter2 = $this->getMockBuilder('Knp\Menu\Matcher\Voter\VoterInterface')->getMock();
$voter2->expects($this->never())
Expand All @@ -105,13 +105,13 @@ public function testVoterIterator(bool $value): void
$item = $this->getMockBuilder('Knp\Menu\ItemInterface')->getMock();
$item->expects($this->any())
->method('isCurrent')
->will($this->returnValue(null));
->willReturn(null);

$voter1 = $this->getMockBuilder('Knp\Menu\Matcher\Voter\VoterInterface')->getMock();
$voter1->expects($this->once())
->method('matchItem')
->with($this->equalTo($item))
->will($this->returnValue($value));
->willReturn($value);

$voter2 = $this->getMockBuilder('Knp\Menu\Matcher\Voter\VoterInterface')->getMock();
$voter2->expects($this->never())
Expand Down
4 changes: 2 additions & 2 deletions tests/Knp/Menu/Tests/Matcher/Voter/RegexVoterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Knp\Menu\Matcher\Voter\RegexVoter;
use PHPUnit\Framework\TestCase;

class RegexVoterTest extends TestCase
final class RegexVoterTest extends TestCase
{
/**
* @param string $exp
Expand All @@ -19,7 +19,7 @@ public function testMatching($exp, $itemUri, $expected): void
$item = $this->getMockBuilder('Knp\Menu\ItemInterface')->getMock();
$item->expects($this->any())
->method('getUri')
->will($this->returnValue($itemUri));
->willReturn($itemUri);

$voter = new RegexVoter($exp);

Expand Down

0 comments on commit 2d54f8e

Please sign in to comment.