SlugifyExtensionTest.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. namespace Cocur\Slugify\Tests\Bridge\Nette;
  3. use Cocur\Slugify\Bridge\Nette\SlugifyExtension;
  4. use Mockery as m;
  5. use Mockery\Adapter\Phpunit\MockeryTestCase;
  6. /**
  7. * SlugifyExtensionTest
  8. *
  9. * @category test
  10. * @package cocur/slugify
  11. * @subpackage bridge
  12. * @author Lukáš Unger <looky.msc@gmail.com>
  13. * @license http://www.opensource.org/licenses/MIT The MIT License
  14. * @group unit
  15. */
  16. class SlugifyExtensionTest extends MockeryTestCase
  17. {
  18. protected function setUp(): void
  19. {
  20. $this->extension = new SlugifyExtension();
  21. }
  22. /**
  23. * @covers \Cocur\Slugify\Bridge\Nette\SlugifyExtension::loadConfiguration()
  24. */
  25. public function testLoadConfiguration()
  26. {
  27. $slugify = m::mock('Nette\DI\ServiceDefinition');
  28. $slugify
  29. ->shouldReceive('setClass')
  30. ->with('Cocur\Slugify\SlugifyInterface')
  31. ->once()
  32. ->andReturn($slugify);
  33. $slugify
  34. ->shouldReceive('setFactory')
  35. ->with('Cocur\Slugify\Slugify')
  36. ->once()
  37. ->andReturn($slugify);
  38. $helper = m::mock('Nette\DI\ServiceDefinition');
  39. $helper
  40. ->shouldReceive('setClass')
  41. ->with('Cocur\Slugify\Bridge\Latte\SlugifyHelper')
  42. ->once()
  43. ->andReturn($helper);
  44. $helper
  45. ->shouldReceive('setAutowired')
  46. ->with(false)
  47. ->once()
  48. ->andReturn($helper);
  49. $builder = m::mock('Nette\DI\ContainerBuilder');
  50. $builder
  51. ->shouldReceive('addDefinition')
  52. ->with('slugify.slugify')
  53. ->once()
  54. ->andReturn($slugify);
  55. $builder
  56. ->shouldReceive('addDefinition')
  57. ->with('slugify.helper')
  58. ->once()
  59. ->andReturn($helper);
  60. $compiler = m::mock('Nette\DI\Compiler');
  61. $compiler
  62. ->shouldReceive('getContainerBuilder')
  63. ->once()
  64. ->andReturn($builder);
  65. $this->extension->setCompiler($compiler, 'slugify');
  66. $this->extension->loadConfiguration();
  67. }
  68. /**
  69. * @covers \Cocur\Slugify\Bridge\Nette\SlugifyExtension::beforeCompile()
  70. */
  71. public function testBeforeCompile()
  72. {
  73. $latteFactory = m::mock('Nette\DI\ServiceDefinition');
  74. $latteFactory
  75. ->shouldReceive('addSetup')
  76. ->with('addFilter', ['slugify', ['@slugify.helper', 'slugify']])
  77. ->once()
  78. ->andReturn($latteFactory);
  79. $latte = m::mock('Nette\DI\ServiceDefinition');
  80. $latte
  81. ->shouldReceive('addSetup')
  82. ->with('addFilter', ['slugify', ['@slugify.helper', 'slugify']])
  83. ->once()
  84. ->andReturn($latte);
  85. $builder = m::mock('Nette\DI\ContainerBuilder');
  86. $builder
  87. ->shouldReceive('getByType')
  88. ->with('Nette\Bridges\ApplicationLatte\ILatteFactory')
  89. ->once()
  90. ->andReturn('latte.latteFactory');
  91. $builder
  92. ->shouldReceive('hasDefinition')
  93. ->with('latte.latteFactory')
  94. ->once()
  95. ->andReturn(true);
  96. $builder
  97. ->shouldReceive('getDefinition')
  98. ->with('latte.latteFactory')
  99. ->once()
  100. ->andReturn($latteFactory);
  101. $builder
  102. ->shouldReceive('hasDefinition')
  103. ->with('nette.latte')
  104. ->once()
  105. ->andReturn(true);
  106. $builder
  107. ->shouldReceive('getDefinition')
  108. ->with('nette.latte')
  109. ->once()
  110. ->andReturn($latte);
  111. $compiler = m::mock('Nette\DI\Compiler');
  112. $compiler
  113. ->shouldReceive('getContainerBuilder')
  114. ->once()
  115. ->andReturn($builder);
  116. $this->extension->setCompiler($compiler, 'slugify');
  117. $this->extension->beforeCompile();
  118. }
  119. }