GetSetMethodNormalizerTest.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Serializer\Tests\Normalizer;
  11. use Doctrine\Common\Annotations\AnnotationReader;
  12. use Symfony\Component\Serializer\NameConverter\CamelCaseToSnakeCaseNameConverter;
  13. use Symfony\Component\Serializer\Normalizer\GetSetMethodNormalizer;
  14. use Symfony\Component\Serializer\Serializer;
  15. use Symfony\Component\Serializer\SerializerInterface;
  16. use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
  17. use Symfony\Component\Serializer\Tests\Fixtures\CircularReferenceDummy;
  18. use Symfony\Component\Serializer\Tests\Fixtures\MaxDepthDummy;
  19. use Symfony\Component\Serializer\Tests\Fixtures\SiblingHolder;
  20. use Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader;
  21. use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory;
  22. use Symfony\Component\Serializer\Tests\Fixtures\GroupDummy;
  23. class GetSetMethodNormalizerTest extends \PHPUnit_Framework_TestCase
  24. {
  25. /**
  26. * @var GetSetMethodNormalizer
  27. */
  28. private $normalizer;
  29. /**
  30. * @var SerializerInterface
  31. */
  32. private $serializer;
  33. protected function setUp()
  34. {
  35. $this->serializer = $this->getMockBuilder(__NAMESPACE__.'\SerializerNormalizer')->getMock();
  36. $this->normalizer = new GetSetMethodNormalizer();
  37. $this->normalizer->setSerializer($this->serializer);
  38. }
  39. public function testInterface()
  40. {
  41. $this->assertInstanceOf('Symfony\Component\Serializer\Normalizer\NormalizerInterface', $this->normalizer);
  42. $this->assertInstanceOf('Symfony\Component\Serializer\Normalizer\DenormalizerInterface', $this->normalizer);
  43. }
  44. public function testNormalize()
  45. {
  46. $obj = new GetSetDummy();
  47. $object = new \stdClass();
  48. $obj->setFoo('foo');
  49. $obj->setBar('bar');
  50. $obj->setBaz(true);
  51. $obj->setCamelCase('camelcase');
  52. $obj->setObject($object);
  53. $this->serializer
  54. ->expects($this->once())
  55. ->method('normalize')
  56. ->with($object, 'any')
  57. ->will($this->returnValue('string_object'))
  58. ;
  59. $this->assertEquals(
  60. array(
  61. 'foo' => 'foo',
  62. 'bar' => 'bar',
  63. 'baz' => true,
  64. 'fooBar' => 'foobar',
  65. 'camelCase' => 'camelcase',
  66. 'object' => 'string_object',
  67. ),
  68. $this->normalizer->normalize($obj, 'any')
  69. );
  70. }
  71. public function testDenormalize()
  72. {
  73. $obj = $this->normalizer->denormalize(
  74. array('foo' => 'foo', 'bar' => 'bar', 'baz' => true, 'fooBar' => 'foobar'),
  75. __NAMESPACE__.'\GetSetDummy',
  76. 'any'
  77. );
  78. $this->assertEquals('foo', $obj->getFoo());
  79. $this->assertEquals('bar', $obj->getBar());
  80. $this->assertTrue($obj->isBaz());
  81. }
  82. public function testDenormalizeWithObject()
  83. {
  84. $data = new \stdClass();
  85. $data->foo = 'foo';
  86. $data->bar = 'bar';
  87. $data->fooBar = 'foobar';
  88. $obj = $this->normalizer->denormalize($data, __NAMESPACE__.'\GetSetDummy', 'any');
  89. $this->assertEquals('foo', $obj->getFoo());
  90. $this->assertEquals('bar', $obj->getBar());
  91. }
  92. public function testDenormalizeNull()
  93. {
  94. $this->assertEquals(new GetSetDummy(), $this->normalizer->denormalize(null, __NAMESPACE__.'\GetSetDummy'));
  95. }
  96. public function testConstructorDenormalize()
  97. {
  98. $obj = $this->normalizer->denormalize(
  99. array('foo' => 'foo', 'bar' => 'bar', 'baz' => true, 'fooBar' => 'foobar'),
  100. __NAMESPACE__.'\GetConstructorDummy', 'any');
  101. $this->assertEquals('foo', $obj->getFoo());
  102. $this->assertEquals('bar', $obj->getBar());
  103. $this->assertTrue($obj->isBaz());
  104. }
  105. public function testConstructorDenormalizeWithNullArgument()
  106. {
  107. $obj = $this->normalizer->denormalize(
  108. array('foo' => 'foo', 'bar' => null, 'baz' => true),
  109. __NAMESPACE__.'\GetConstructorDummy', 'any');
  110. $this->assertEquals('foo', $obj->getFoo());
  111. $this->assertNull($obj->getBar());
  112. $this->assertTrue($obj->isBaz());
  113. }
  114. public function testConstructorDenormalizeWithMissingOptionalArgument()
  115. {
  116. $obj = $this->normalizer->denormalize(
  117. array('foo' => 'test', 'baz' => array(1, 2, 3)),
  118. __NAMESPACE__.'\GetConstructorOptionalArgsDummy', 'any');
  119. $this->assertEquals('test', $obj->getFoo());
  120. $this->assertEquals(array(), $obj->getBar());
  121. $this->assertEquals(array(1, 2, 3), $obj->getBaz());
  122. }
  123. public function testConstructorDenormalizeWithOptionalDefaultArgument()
  124. {
  125. $obj = $this->normalizer->denormalize(
  126. array('bar' => 'test'),
  127. __NAMESPACE__.'\GetConstructorArgsWithDefaultValueDummy', 'any');
  128. $this->assertEquals(array(), $obj->getFoo());
  129. $this->assertEquals('test', $obj->getBar());
  130. }
  131. /**
  132. * @requires PHP 5.6
  133. */
  134. public function testConstructorDenormalizeWithVariadicArgument()
  135. {
  136. $obj = $this->normalizer->denormalize(
  137. array('foo' => array(1, 2, 3)),
  138. 'Symfony\Component\Serializer\Tests\Fixtures\VariadicConstructorArgsDummy', 'any');
  139. $this->assertEquals(array(1, 2, 3), $obj->getFoo());
  140. }
  141. /**
  142. * @requires PHP 5.6
  143. */
  144. public function testConstructorDenormalizeWithMissingVariadicArgument()
  145. {
  146. $obj = $this->normalizer->denormalize(
  147. array(),
  148. 'Symfony\Component\Serializer\Tests\Fixtures\VariadicConstructorArgsDummy', 'any');
  149. $this->assertEquals(array(), $obj->getFoo());
  150. }
  151. public function testConstructorWithObjectDenormalize()
  152. {
  153. $data = new \stdClass();
  154. $data->foo = 'foo';
  155. $data->bar = 'bar';
  156. $data->baz = true;
  157. $data->fooBar = 'foobar';
  158. $obj = $this->normalizer->denormalize($data, __NAMESPACE__.'\GetConstructorDummy', 'any');
  159. $this->assertEquals('foo', $obj->getFoo());
  160. $this->assertEquals('bar', $obj->getBar());
  161. }
  162. public function testConstructorWArgWithPrivateMutator()
  163. {
  164. $obj = $this->normalizer->denormalize(array('foo' => 'bar'), __NAMESPACE__.'\ObjectConstructorArgsWithPrivateMutatorDummy', 'any');
  165. $this->assertEquals('bar', $obj->getFoo());
  166. }
  167. public function testGroupsNormalize()
  168. {
  169. $classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
  170. $this->normalizer = new GetSetMethodNormalizer($classMetadataFactory);
  171. $this->normalizer->setSerializer($this->serializer);
  172. $obj = new GroupDummy();
  173. $obj->setFoo('foo');
  174. $obj->setBar('bar');
  175. $obj->setFooBar('fooBar');
  176. $obj->setSymfony('symfony');
  177. $obj->setKevin('kevin');
  178. $obj->setCoopTilleuls('coopTilleuls');
  179. $this->assertEquals(array(
  180. 'bar' => 'bar',
  181. ), $this->normalizer->normalize($obj, null, array(GetSetMethodNormalizer::GROUPS => array('c'))));
  182. $this->assertEquals(array(
  183. 'symfony' => 'symfony',
  184. 'foo' => 'foo',
  185. 'fooBar' => 'fooBar',
  186. 'bar' => 'bar',
  187. 'kevin' => 'kevin',
  188. 'coopTilleuls' => 'coopTilleuls',
  189. ), $this->normalizer->normalize($obj, null, array(GetSetMethodNormalizer::GROUPS => array('a', 'c'))));
  190. }
  191. public function testGroupsDenormalize()
  192. {
  193. $classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
  194. $this->normalizer = new GetSetMethodNormalizer($classMetadataFactory);
  195. $this->normalizer->setSerializer($this->serializer);
  196. $obj = new GroupDummy();
  197. $obj->setFoo('foo');
  198. $toNormalize = array('foo' => 'foo', 'bar' => 'bar');
  199. $normalized = $this->normalizer->denormalize(
  200. $toNormalize,
  201. 'Symfony\Component\Serializer\Tests\Fixtures\GroupDummy',
  202. null,
  203. array(GetSetMethodNormalizer::GROUPS => array('a'))
  204. );
  205. $this->assertEquals($obj, $normalized);
  206. $obj->setBar('bar');
  207. $normalized = $this->normalizer->denormalize(
  208. $toNormalize,
  209. 'Symfony\Component\Serializer\Tests\Fixtures\GroupDummy',
  210. null,
  211. array(GetSetMethodNormalizer::GROUPS => array('a', 'b'))
  212. );
  213. $this->assertEquals($obj, $normalized);
  214. }
  215. public function testGroupsNormalizeWithNameConverter()
  216. {
  217. $classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
  218. $this->normalizer = new GetSetMethodNormalizer($classMetadataFactory, new CamelCaseToSnakeCaseNameConverter());
  219. $this->normalizer->setSerializer($this->serializer);
  220. $obj = new GroupDummy();
  221. $obj->setFooBar('@dunglas');
  222. $obj->setSymfony('@coopTilleuls');
  223. $obj->setCoopTilleuls('les-tilleuls.coop');
  224. $this->assertEquals(
  225. array(
  226. 'bar' => null,
  227. 'foo_bar' => '@dunglas',
  228. 'symfony' => '@coopTilleuls',
  229. ),
  230. $this->normalizer->normalize($obj, null, array(GetSetMethodNormalizer::GROUPS => array('name_converter')))
  231. );
  232. }
  233. public function testGroupsDenormalizeWithNameConverter()
  234. {
  235. $classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
  236. $this->normalizer = new GetSetMethodNormalizer($classMetadataFactory, new CamelCaseToSnakeCaseNameConverter());
  237. $this->normalizer->setSerializer($this->serializer);
  238. $obj = new GroupDummy();
  239. $obj->setFooBar('@dunglas');
  240. $obj->setSymfony('@coopTilleuls');
  241. $this->assertEquals(
  242. $obj,
  243. $this->normalizer->denormalize(array(
  244. 'bar' => null,
  245. 'foo_bar' => '@dunglas',
  246. 'symfony' => '@coopTilleuls',
  247. 'coop_tilleuls' => 'les-tilleuls.coop',
  248. ), 'Symfony\Component\Serializer\Tests\Fixtures\GroupDummy', null, array(GetSetMethodNormalizer::GROUPS => array('name_converter')))
  249. );
  250. }
  251. /**
  252. * @dataProvider provideCallbacks
  253. */
  254. public function testCallbacks($callbacks, $value, $result, $message)
  255. {
  256. $this->normalizer->setCallbacks($callbacks);
  257. $obj = new GetConstructorDummy('', $value, true);
  258. $this->assertEquals(
  259. $result,
  260. $this->normalizer->normalize($obj, 'any'),
  261. $message
  262. );
  263. }
  264. /**
  265. * @expectedException \InvalidArgumentException
  266. */
  267. public function testUncallableCallbacks()
  268. {
  269. $this->normalizer->setCallbacks(array('bar' => null));
  270. $obj = new GetConstructorDummy('baz', 'quux', true);
  271. $this->normalizer->normalize($obj, 'any');
  272. }
  273. public function testIgnoredAttributes()
  274. {
  275. $this->normalizer->setIgnoredAttributes(array('foo', 'bar', 'baz', 'camelCase', 'object'));
  276. $obj = new GetSetDummy();
  277. $obj->setFoo('foo');
  278. $obj->setBar('bar');
  279. $obj->setBaz(true);
  280. $this->assertEquals(
  281. array('fooBar' => 'foobar'),
  282. $this->normalizer->normalize($obj, 'any')
  283. );
  284. }
  285. public function provideCallbacks()
  286. {
  287. return array(
  288. array(
  289. array(
  290. 'bar' => function ($bar) {
  291. return 'baz';
  292. },
  293. ),
  294. 'baz',
  295. array('foo' => '', 'bar' => 'baz', 'baz' => true),
  296. 'Change a string',
  297. ),
  298. array(
  299. array(
  300. 'bar' => function ($bar) {
  301. },
  302. ),
  303. 'baz',
  304. array('foo' => '', 'bar' => null, 'baz' => true),
  305. 'Null an item',
  306. ),
  307. array(
  308. array(
  309. 'bar' => function ($bar) {
  310. return $bar->format('d-m-Y H:i:s');
  311. },
  312. ),
  313. new \DateTime('2011-09-10 06:30:00'),
  314. array('foo' => '', 'bar' => '10-09-2011 06:30:00', 'baz' => true),
  315. 'Format a date',
  316. ),
  317. array(
  318. array(
  319. 'bar' => function ($bars) {
  320. $foos = '';
  321. foreach ($bars as $bar) {
  322. $foos .= $bar->getFoo();
  323. }
  324. return $foos;
  325. },
  326. ),
  327. array(new GetConstructorDummy('baz', '', false), new GetConstructorDummy('quux', '', false)),
  328. array('foo' => '', 'bar' => 'bazquux', 'baz' => true),
  329. 'Collect a property',
  330. ),
  331. array(
  332. array(
  333. 'bar' => function ($bars) {
  334. return count($bars);
  335. },
  336. ),
  337. array(new GetConstructorDummy('baz', '', false), new GetConstructorDummy('quux', '', false)),
  338. array('foo' => '', 'bar' => 2, 'baz' => true),
  339. 'Count a property',
  340. ),
  341. );
  342. }
  343. /**
  344. * @expectedException \Symfony\Component\Serializer\Exception\LogicException
  345. * @expectedExceptionMessage Cannot normalize attribute "object" because the injected serializer is not a normalizer
  346. */
  347. public function testUnableToNormalizeObjectAttribute()
  348. {
  349. $serializer = $this->getMockBuilder('Symfony\Component\Serializer\SerializerInterface')->getMock();
  350. $this->normalizer->setSerializer($serializer);
  351. $obj = new GetSetDummy();
  352. $object = new \stdClass();
  353. $obj->setObject($object);
  354. $this->normalizer->normalize($obj, 'any');
  355. }
  356. /**
  357. * @expectedException \Symfony\Component\Serializer\Exception\CircularReferenceException
  358. */
  359. public function testUnableToNormalizeCircularReference()
  360. {
  361. $serializer = new Serializer(array($this->normalizer));
  362. $this->normalizer->setSerializer($serializer);
  363. $this->normalizer->setCircularReferenceLimit(2);
  364. $obj = new CircularReferenceDummy();
  365. $this->normalizer->normalize($obj);
  366. }
  367. public function testSiblingReference()
  368. {
  369. $serializer = new Serializer(array($this->normalizer));
  370. $this->normalizer->setSerializer($serializer);
  371. $siblingHolder = new SiblingHolder();
  372. $expected = array(
  373. 'sibling0' => array('coopTilleuls' => 'Les-Tilleuls.coop'),
  374. 'sibling1' => array('coopTilleuls' => 'Les-Tilleuls.coop'),
  375. 'sibling2' => array('coopTilleuls' => 'Les-Tilleuls.coop'),
  376. );
  377. $this->assertEquals($expected, $this->normalizer->normalize($siblingHolder));
  378. }
  379. public function testCircularReferenceHandler()
  380. {
  381. $serializer = new Serializer(array($this->normalizer));
  382. $this->normalizer->setSerializer($serializer);
  383. $this->normalizer->setCircularReferenceHandler(function ($obj) {
  384. return get_class($obj);
  385. });
  386. $obj = new CircularReferenceDummy();
  387. $expected = array('me' => 'Symfony\Component\Serializer\Tests\Fixtures\CircularReferenceDummy');
  388. $this->assertEquals($expected, $this->normalizer->normalize($obj));
  389. }
  390. public function testObjectToPopulate()
  391. {
  392. $dummy = new GetSetDummy();
  393. $dummy->setFoo('foo');
  394. $obj = $this->normalizer->denormalize(
  395. array('bar' => 'bar'),
  396. __NAMESPACE__.'\GetSetDummy',
  397. null,
  398. array(GetSetMethodNormalizer::OBJECT_TO_POPULATE => $dummy)
  399. );
  400. $this->assertEquals($dummy, $obj);
  401. $this->assertEquals('foo', $obj->getFoo());
  402. $this->assertEquals('bar', $obj->getBar());
  403. }
  404. public function testDenormalizeNonExistingAttribute()
  405. {
  406. $this->assertEquals(
  407. new GetSetDummy(),
  408. $this->normalizer->denormalize(array('non_existing' => true), __NAMESPACE__.'\GetSetDummy')
  409. );
  410. }
  411. public function testDenormalizeShouldNotSetStaticAttribute()
  412. {
  413. $obj = $this->normalizer->denormalize(array('staticObject' => true), __NAMESPACE__.'\GetSetDummy');
  414. $this->assertEquals(new GetSetDummy(), $obj);
  415. $this->assertNull(GetSetDummy::getStaticObject());
  416. }
  417. public function testNoTraversableSupport()
  418. {
  419. $this->assertFalse($this->normalizer->supportsNormalization(new \ArrayObject()));
  420. }
  421. public function testNoStaticGetSetSupport()
  422. {
  423. $this->assertFalse($this->normalizer->supportsNormalization(new ObjectWithJustStaticSetterDummy()));
  424. }
  425. public function testPrivateSetter()
  426. {
  427. $obj = $this->normalizer->denormalize(array('foo' => 'foobar'), __NAMESPACE__.'\ObjectWithPrivateSetterDummy');
  428. $this->assertEquals('bar', $obj->getFoo());
  429. }
  430. public function testMaxDepth()
  431. {
  432. $classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
  433. $this->normalizer = new GetSetMethodNormalizer($classMetadataFactory);
  434. $serializer = new Serializer(array($this->normalizer));
  435. $this->normalizer->setSerializer($serializer);
  436. $level1 = new MaxDepthDummy();
  437. $level1->bar = 'level1';
  438. $level2 = new MaxDepthDummy();
  439. $level2->bar = 'level2';
  440. $level1->child = $level2;
  441. $level3 = new MaxDepthDummy();
  442. $level3->bar = 'level3';
  443. $level2->child = $level3;
  444. $level4 = new MaxDepthDummy();
  445. $level4->bar = 'level4';
  446. $level3->child = $level4;
  447. $result = $serializer->normalize($level1, null, array(GetSetMethodNormalizer::ENABLE_MAX_DEPTH => true));
  448. $expected = array(
  449. 'bar' => 'level1',
  450. 'child' => array(
  451. 'bar' => 'level2',
  452. 'child' => array(
  453. 'bar' => 'level3',
  454. 'child' => array(
  455. 'child' => null,
  456. ),
  457. ),
  458. ),
  459. );
  460. $this->assertEquals($expected, $result);
  461. }
  462. }
  463. class GetSetDummy
  464. {
  465. protected $foo;
  466. private $bar;
  467. private $baz;
  468. protected $camelCase;
  469. protected $object;
  470. private static $staticObject;
  471. public function getFoo()
  472. {
  473. return $this->foo;
  474. }
  475. public function setFoo($foo)
  476. {
  477. $this->foo = $foo;
  478. }
  479. public function getBar()
  480. {
  481. return $this->bar;
  482. }
  483. public function setBar($bar)
  484. {
  485. $this->bar = $bar;
  486. }
  487. public function isBaz()
  488. {
  489. return $this->baz;
  490. }
  491. public function setBaz($baz)
  492. {
  493. $this->baz = $baz;
  494. }
  495. public function getFooBar()
  496. {
  497. return $this->foo.$this->bar;
  498. }
  499. public function getCamelCase()
  500. {
  501. return $this->camelCase;
  502. }
  503. public function setCamelCase($camelCase)
  504. {
  505. $this->camelCase = $camelCase;
  506. }
  507. public function otherMethod()
  508. {
  509. throw new \RuntimeException('Dummy::otherMethod() should not be called');
  510. }
  511. public function setObject($object)
  512. {
  513. $this->object = $object;
  514. }
  515. public function getObject()
  516. {
  517. return $this->object;
  518. }
  519. public static function getStaticObject()
  520. {
  521. return self::$staticObject;
  522. }
  523. public static function setStaticObject($object)
  524. {
  525. self::$staticObject = $object;
  526. }
  527. protected function getPrivate()
  528. {
  529. throw new \RuntimeException('Dummy::getPrivate() should not be called');
  530. }
  531. }
  532. class GetConstructorDummy
  533. {
  534. protected $foo;
  535. private $bar;
  536. private $baz;
  537. public function __construct($foo, $bar, $baz)
  538. {
  539. $this->foo = $foo;
  540. $this->bar = $bar;
  541. $this->baz = $baz;
  542. }
  543. public function getFoo()
  544. {
  545. return $this->foo;
  546. }
  547. public function getBar()
  548. {
  549. return $this->bar;
  550. }
  551. public function isBaz()
  552. {
  553. return $this->baz;
  554. }
  555. public function otherMethod()
  556. {
  557. throw new \RuntimeException('Dummy::otherMethod() should not be called');
  558. }
  559. }
  560. abstract class SerializerNormalizer implements SerializerInterface, NormalizerInterface
  561. {
  562. }
  563. class GetConstructorOptionalArgsDummy
  564. {
  565. protected $foo;
  566. private $bar;
  567. private $baz;
  568. public function __construct($foo, $bar = array(), $baz = array())
  569. {
  570. $this->foo = $foo;
  571. $this->bar = $bar;
  572. $this->baz = $baz;
  573. }
  574. public function getFoo()
  575. {
  576. return $this->foo;
  577. }
  578. public function getBar()
  579. {
  580. return $this->bar;
  581. }
  582. public function getBaz()
  583. {
  584. return $this->baz;
  585. }
  586. public function otherMethod()
  587. {
  588. throw new \RuntimeException('Dummy::otherMethod() should not be called');
  589. }
  590. }
  591. class GetConstructorArgsWithDefaultValueDummy
  592. {
  593. protected $foo;
  594. protected $bar;
  595. public function __construct($foo = array(), $bar)
  596. {
  597. $this->foo = $foo;
  598. $this->bar = $bar;
  599. }
  600. public function getFoo()
  601. {
  602. return $this->foo;
  603. }
  604. public function getBar()
  605. {
  606. return $this->bar;
  607. }
  608. public function otherMethod()
  609. {
  610. throw new \RuntimeException('Dummy::otherMethod() should not be called');
  611. }
  612. }
  613. class GetCamelizedDummy
  614. {
  615. private $kevinDunglas;
  616. private $fooBar;
  617. private $bar_foo;
  618. public function __construct($kevinDunglas = null)
  619. {
  620. $this->kevinDunglas = $kevinDunglas;
  621. }
  622. public function getKevinDunglas()
  623. {
  624. return $this->kevinDunglas;
  625. }
  626. public function setFooBar($fooBar)
  627. {
  628. $this->fooBar = $fooBar;
  629. }
  630. public function getFooBar()
  631. {
  632. return $this->fooBar;
  633. }
  634. public function setBar_foo($bar_foo)
  635. {
  636. $this->bar_foo = $bar_foo;
  637. }
  638. public function getBar_foo()
  639. {
  640. return $this->bar_foo;
  641. }
  642. }
  643. class ObjectConstructorArgsWithPrivateMutatorDummy
  644. {
  645. private $foo;
  646. public function __construct($foo)
  647. {
  648. $this->setFoo($foo);
  649. }
  650. public function getFoo()
  651. {
  652. return $this->foo;
  653. }
  654. private function setFoo($foo)
  655. {
  656. $this->foo = $foo;
  657. }
  658. }
  659. class ObjectWithPrivateSetterDummy
  660. {
  661. private $foo = 'bar';
  662. public function getFoo()
  663. {
  664. return $this->foo;
  665. }
  666. private function setFoo($foo)
  667. {
  668. }
  669. }
  670. class ObjectWithJustStaticSetterDummy
  671. {
  672. private static $foo = 'bar';
  673. public static function getFoo()
  674. {
  675. return self::$foo;
  676. }
  677. public static function setFoo($foo)
  678. {
  679. self::$foo = $foo;
  680. }
  681. }