PropertyAccessorBuilderTest.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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\PropertyAccess\Tests;
  11. use PHPUnit\Framework\TestCase;
  12. use Symfony\Component\Cache\Adapter\ArrayAdapter;
  13. use Symfony\Component\PropertyAccess\PropertyAccessor;
  14. use Symfony\Component\PropertyAccess\PropertyAccessorBuilder;
  15. class PropertyAccessorBuilderTest extends TestCase
  16. {
  17. /**
  18. * @var PropertyAccessorBuilder
  19. */
  20. protected $builder;
  21. protected function setUp()
  22. {
  23. $this->builder = new PropertyAccessorBuilder();
  24. }
  25. protected function tearDown()
  26. {
  27. $this->builder = null;
  28. }
  29. public function testEnableMagicCall()
  30. {
  31. $this->assertSame($this->builder, $this->builder->enableMagicCall());
  32. }
  33. public function testDisableMagicCall()
  34. {
  35. $this->assertSame($this->builder, $this->builder->disableMagicCall());
  36. }
  37. public function testIsMagicCallEnable()
  38. {
  39. $this->assertFalse($this->builder->isMagicCallEnabled());
  40. $this->assertTrue($this->builder->enableMagicCall()->isMagicCallEnabled());
  41. $this->assertFalse($this->builder->disableMagicCall()->isMagicCallEnabled());
  42. }
  43. public function testGetPropertyAccessor()
  44. {
  45. $this->assertInstanceOf(PropertyAccessor::class, $this->builder->getPropertyAccessor());
  46. $this->assertInstanceOf(PropertyAccessor::class, $this->builder->enableMagicCall()->getPropertyAccessor());
  47. }
  48. public function testUseCache()
  49. {
  50. $cacheItemPool = new ArrayAdapter();
  51. $this->builder->setCacheItemPool($cacheItemPool);
  52. $this->assertEquals($cacheItemPool, $this->builder->getCacheItemPool());
  53. $this->assertInstanceOf(PropertyAccessor::class, $this->builder->getPropertyAccessor());
  54. }
  55. }