Skip to content

Commit

Permalink
minor symfony#29934 ensure compatibility with older PHPUnit mocks (xa…
Browse files Browse the repository at this point in the history
…bbuh)

This PR was merged into the 3.4 branch.

Discussion
----------

ensure compatibility with older PHPUnit mocks

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets |
| License       | MIT
| Doc PR        |

Commits
-------

0d9de7e [Form] ensure compatibility with older PHPUnit mocks
  • Loading branch information
nicolas-grekas committed Jan 25, 2019
2 parents ea7813a + d14aa48 commit a2369c9
Showing 1 changed file with 13 additions and 20 deletions.
33 changes: 13 additions & 20 deletions Tests/Mapping/ClassMetadataTest.php
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\Component\Serializer\Tests\Mapping;

use PHPUnit\Framework\TestCase;
use Symfony\Component\Serializer\Mapping\AttributeMetadata;
use Symfony\Component\Serializer\Mapping\ClassMetadata;

/**
Expand All @@ -29,11 +30,8 @@ public function testAttributeMetadata()
{
$classMetadata = new ClassMetadata('c');

$a1 = $this->getMockBuilder('Symfony\Component\Serializer\Mapping\AttributeMetadataInterface')->getMock();
$a1->method('getName')->willReturn('a1');

$a2 = $this->getMockBuilder('Symfony\Component\Serializer\Mapping\AttributeMetadataInterface')->getMock();
$a2->method('getName')->willReturn('a2');
$a1 = new AttributeMetadata('a1');
$a2 = new AttributeMetadata('a2');

$classMetadata->addAttributeMetadata($a1);
$classMetadata->addAttributeMetadata($a2);
Expand All @@ -46,33 +44,28 @@ public function testMerge()
$classMetadata1 = new ClassMetadata('c1');
$classMetadata2 = new ClassMetadata('c2');

$ac1 = $this->getMockBuilder('Symfony\Component\Serializer\Mapping\AttributeMetadataInterface')->getMock();
$ac1->method('getName')->willReturn('a1');
$ac1->method('getGroups')->willReturn(['a', 'b']);

$ac2 = $this->getMockBuilder('Symfony\Component\Serializer\Mapping\AttributeMetadataInterface')->getMock();
$ac2->method('getName')->willReturn('a1');
$ac2->method('getGroups')->willReturn(['b', 'c']);
$ac1 = new AttributeMetadata('a1');
$ac1->addGroup('a');
$ac1->addGroup('b');
$ac2 = new AttributeMetadata('a1');
$ac2->addGroup('b');
$ac2->addGroup('c');

$classMetadata1->addAttributeMetadata($ac1);
$classMetadata2->addAttributeMetadata($ac2);

$classMetadata1->merge($classMetadata2);

$ac1->method('getGroups')->willReturn('a', 'b', 'c');

$this->assertEquals(['a1' => $ac1], $classMetadata2->getAttributesMetadata());
$this->assertSame(['a', 'b', 'c'], $ac1->getGroups());
$this->assertEquals(['a1' => $ac1], $classMetadata1->getAttributesMetadata());
}

public function testSerialize()
{
$classMetadata = new ClassMetadata('a');

$a1 = $this->getMockBuilder('Symfony\Component\Serializer\Mapping\AttributeMetadataInterface')->getMock();
$a1->method('getName')->willReturn('b1');

$a2 = $this->getMockBuilder('Symfony\Component\Serializer\Mapping\AttributeMetadataInterface')->getMock();
$a2->method('getName')->willReturn('b2');
$a1 = new AttributeMetadata('b1');
$a2 = new AttributeMetadata('b2');

$classMetadata->addAttributeMetadata($a1);
$classMetadata->addAttributeMetadata($a2);
Expand Down

0 comments on commit a2369c9

Please sign in to comment.