1<?php 2 3namespace FINDOLOGIC\Export\Tests; 4 5use FINDOLOGIC\Export\Data\Property; 6use PHPUnit\Framework\TestCase; 7 8class PropertyTest extends TestCase 9{ 10 /** 11 * @expectedException \FINDOLOGIC\Export\Data\DuplicateValueForUsergroupException 12 */ 13 public function testAddingMultipleValuesPerUsergroupCausesException() 14 { 15 $property = new Property('prop'); 16 $property->addValue('foobar', 'usergroup'); 17 $property->addValue('foobar', 'usergroup'); 18 } 19 20 /** 21 * @expectedException \FINDOLOGIC\Export\Data\DuplicateValueForUsergroupException 22 */ 23 public function testAddingMultipleValuesWithoutUsergroupCausesException() 24 { 25 $property = new Property('prop'); 26 $property->addValue('foobar'); 27 $property->addValue('foobar'); 28 } 29 30 public function propertyKeyProvider() 31 { 32 return [ 33 'reserved property "image\d+"' => ['image0', true], 34 'reserved property "thumbnail\d+"' => ['thumbnail1', true], 35 'reserved property "ordernumber"' => ['ordernumber', true], 36 'non-reserved property key' => ['foobar', false] 37 ]; 38 } 39 40 /** 41 * @dataProvider propertyKeyProvider 42 */ 43 public function testReservedPropertyKeysCausesException($key, $shouldCauseException) 44 { 45 try { 46 $property = new Property($key); 47 if ($shouldCauseException) { 48 $this->fail('Using a reserved property key should cause an exception.'); 49 } else { 50 // The following assertion exists mostly to ensure that PHPUnit does not lament 51 // the lack of assertions in this successful test. 52 $this->assertNotNull($property); 53 } 54 } catch (\Exception $exception) { 55 $this->assertRegExp('/' . $key . '/', $exception->getMessage()); 56 } 57 } 58} 59