Skip to content

Commit

Permalink
Fix merging of routes for subclasses (#1)
Browse files Browse the repository at this point in the history
* Fix merging of routes for subclasses

* Fix PHPUnit 5.x deprecation warnings
  • Loading branch information
mpdude authored Sep 29, 2020
1 parent aacc17f commit 721e81d
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 4 deletions.
7 changes: 7 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,12 @@
"psr-0": {
"JMS": "src/"
}
},

"autoload-dev": {
"psr-0": {
"JMS\\Tests": "tests/"
}
}

}
9 changes: 8 additions & 1 deletion src/JMS/ObjectRouting/Metadata/ClassMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
namespace JMS\ObjectRouting\Metadata;

use Metadata\MergeableClassMetadata;
use Metadata\MergeableInterface;

class ClassMetadata extends MergeableClassMetadata
{
Expand All @@ -32,6 +33,12 @@ public function addRoute($type, $name, array $params = array())
);
}

public function merge(MergeableInterface $object)
{
parent::merge($object);
$this->routes = array_merge($this->routes, $object->routes);
}

public function serialize()
{
return serialize(
Expand All @@ -52,4 +59,4 @@ public function unserialize($str)
parent::unserialize($parentStr);
}

}
}
22 changes: 22 additions & 0 deletions tests/JMS/Tests/ObjectRouting/Metadata/ClassMetadataTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace JMS\Tests\ObjectRouting\Metadata;

use JMS\ObjectRouting\Metadata\ClassMetadata;

class ClassMetadataTest extends \PHPUnit_Framework_TestCase
{
public function testMerge()
{
$base = new ClassMetadata(\PHPUnit_Framework_TestCase::class);
$base->addRoute('test', 'base-route');

$merged = new ClassMetadata(self::class);
$merged->addRoute('test', 'merged-route');

$base->merge($merged);

$this->assertEquals(self::class, $base->name);
$this->assertEquals(['test' => ['name' => 'merged-route', 'params' => []]], $base->routes);
}
}
4 changes: 2 additions & 2 deletions tests/JMS/Tests/ObjectRouting/ObjectRouterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ public function testGenerateNoMetadata()
protected function setUp()
{
$this->router = new ObjectRouter(
$this->adapter = $this->getMock('JMS\ObjectRouting\RouterInterface'),
$this->factory = $this->getMock('Metadata\MetadataFactoryInterface')
$this->adapter = $this->createMock('JMS\ObjectRouting\RouterInterface'),
$this->factory = $this->createMock('Metadata\MetadataFactoryInterface')
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function testGenerate()
protected function setUp()
{
$this->adapter = new Symfony22Adapter(
$this->router = $this->getMock('Symfony\Component\Routing\RouterInterface')
$this->router = $this->createMock('Symfony\Component\Routing\RouterInterface')
);
}
}

0 comments on commit 721e81d

Please sign in to comment.