1<?php 2 3declare(strict_types=1); 4 5namespace JMS\Serializer\Tests\Exclusion; 6 7use JMS\Serializer\Exclusion\GroupsExclusionStrategy; 8use JMS\Serializer\Metadata\StaticPropertyMetadata; 9use JMS\Serializer\SerializationContext; 10use PHPUnit\Framework\TestCase; 11 12class GroupsExclusionStrategyTest extends TestCase 13{ 14 /** 15 * @param array $propertyGroups 16 * @param array $groups 17 * @param bool $exclude 18 * 19 * @dataProvider getExclusionRules 20 */ 21 public function testUninitializedContextIsWorking(array $propertyGroups, array $groups, $exclude) 22 { 23 $metadata = new StaticPropertyMetadata('stdClass', 'prop', 'propVal'); 24 $metadata->groups = $propertyGroups; 25 26 $strat = new GroupsExclusionStrategy($groups); 27 self::assertEquals($strat->shouldSkipProperty($metadata, SerializationContext::create()), $exclude); 28 } 29 30 public function getExclusionRules() 31 { 32 return [ 33 [['foo'], ['foo'], false], 34 [['foo'], [], true], 35 [[], ['foo'], true], 36 [['foo'], ['bar'], true], 37 [['bar'], ['foo'], true], 38 39 [['foo', GroupsExclusionStrategy::DEFAULT_GROUP], [], false], 40 [['foo', 'bar'], [], true], 41 [['foo', 'bar'], [GroupsExclusionStrategy::DEFAULT_GROUP], true], 42 [['foo', 'bar'], ['foo'], false], 43 44 [['foo', GroupsExclusionStrategy::DEFAULT_GROUP], ['test'], true], 45 [['foo', GroupsExclusionStrategy::DEFAULT_GROUP, 'test'], ['test'], false], 46 47 [['foo'], [GroupsExclusionStrategy::DEFAULT_GROUP], true], 48 [[GroupsExclusionStrategy::DEFAULT_GROUP], [], false], 49 [[], [GroupsExclusionStrategy::DEFAULT_GROUP], false], 50 [[GroupsExclusionStrategy::DEFAULT_GROUP], [GroupsExclusionStrategy::DEFAULT_GROUP], false], 51 [[GroupsExclusionStrategy::DEFAULT_GROUP, 'foo'], [GroupsExclusionStrategy::DEFAULT_GROUP], false], 52 [[GroupsExclusionStrategy::DEFAULT_GROUP], [GroupsExclusionStrategy::DEFAULT_GROUP, 'foo'], false], 53 [['foo'], [GroupsExclusionStrategy::DEFAULT_GROUP, 'foo'], false], 54 ]; 55 } 56} 57