CocurSlugifyExtensionTest.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. /**
  3. * This file is part of cocur/slugify.
  4. *
  5. * (c) Florian Eckerstorfer <florian@eckerstorfer.co>
  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 Cocur\Slugify\Tests\Bridge\Symfony;
  11. use Cocur\Slugify\Bridge\Symfony\CocurSlugifyExtension;
  12. use Cocur\Slugify\SlugifyInterface;
  13. use PHPUnit\Framework\TestCase;
  14. use Symfony\Component\DependencyInjection\ContainerBuilder;
  15. use Symfony\Component\DependencyInjection\Definition;
  16. /**
  17. * CocurSlugifyExtensionTest
  18. *
  19. * @category test
  20. * @package cocur/slugify
  21. * @subpackage bridge
  22. * @author Florian Eckerstorfer <florian@eckerstorfer.co>
  23. * @copyright 2012-2014 Florian Eckerstorfer
  24. * @license http://www.opensource.org/licenses/MIT The MIT License
  25. * @group unit
  26. */
  27. class CocurSlugifyExtensionTest extends TestCase
  28. {
  29. protected function setUp(): void
  30. {
  31. $this->extension = new CocurSlugifyExtension();
  32. }
  33. /**
  34. * @covers \Cocur\Slugify\Bridge\Symfony\CocurSlugifyExtension::load()
  35. */
  36. public function testLoad()
  37. {
  38. $twigDefinition = $this->createMock(Definition::class);
  39. $twigDefinition
  40. ->expects($this->once())
  41. ->method('addTag')
  42. ->with($this->equalTo('twig.extension'))
  43. ->willReturn($twigDefinition);
  44. $twigDefinition
  45. ->expects($this->once())
  46. ->method('setPublic')
  47. ->with($this->equalTo(false))
  48. ->willReturn($twigDefinition);
  49. $container = $this->createMock(ContainerBuilder::class);
  50. $container
  51. ->expects($this->exactly(2))
  52. ->method('setDefinition')
  53. ->withConsecutive(
  54. [$this->equalTo('cocur_slugify'), $this->isInstanceOf(Definition::class)],
  55. [$this->equalTo('cocur_slugify.twig.slugify'), $this->isInstanceOf(Definition::class)]
  56. )
  57. ->willReturnOnConsecutiveCalls(
  58. $this->createMock(Definition::class),
  59. $twigDefinition
  60. );
  61. $container
  62. ->expects($this->exactly(2))
  63. ->method('setAlias')
  64. ->withConsecutive(
  65. [$this->equalTo('slugify'), $this->equalTo('cocur_slugify')],
  66. [$this->equalTo(SlugifyInterface::class), $this->equalTo('cocur_slugify')]
  67. );
  68. $this->extension->load([], $container);
  69. }
  70. }