SlugifyExtensionTest.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. namespace Cocur\Slugify\Tests\Bridge\Nette;
  3. use Cocur\Slugify\Bridge\Nette\SlugifyExtension;
  4. use Mockery as m;
  5. /**
  6. * SlugifyExtensionTest
  7. *
  8. * @category test
  9. * @package cocur/slugify
  10. * @subpackage bridge
  11. * @author Lukáš Unger <looky.msc@gmail.com>
  12. * @license http://www.opensource.org/licenses/MIT The MIT License
  13. * @group unit
  14. */
  15. class SlugifyExtensionTest extends \PHPUnit_Framework_TestCase
  16. {
  17. protected function setUp()
  18. {
  19. $this->extension = new SlugifyExtension();
  20. }
  21. /**
  22. * @test
  23. * @covers Cocur\Slugify\Bridge\Nette\SlugifyExtension::loadConfiguration()
  24. */
  25. public function loadConfiguration()
  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. * @test
  70. * @covers Cocur\Slugify\Bridge\Nette\SlugifyExtension::beforeCompile()
  71. */
  72. public function beforeCompile()
  73. {
  74. $latteFactory = m::mock('Nette\DI\ServiceDefinition');
  75. $latteFactory
  76. ->shouldReceive('addSetup')
  77. ->with('addFilter', ['slugify', ['@slugify.helper', 'slugify']])
  78. ->once()
  79. ->andReturn($latteFactory);
  80. $latte = m::mock('Nette\DI\ServiceDefinition');
  81. $latte
  82. ->shouldReceive('addSetup')
  83. ->with('addFilter', ['slugify', ['@slugify.helper', 'slugify']])
  84. ->once()
  85. ->andReturn($latte);
  86. $builder = m::mock('Nette\DI\ContainerBuilder');
  87. $builder
  88. ->shouldReceive('getByType')
  89. ->with('Nette\Bridges\ApplicationLatte\ILatteFactory')
  90. ->once()
  91. ->andReturn('latte.latteFactory');
  92. $builder
  93. ->shouldReceive('hasDefinition')
  94. ->with('latte.latteFactory')
  95. ->once()
  96. ->andReturn(true);
  97. $builder
  98. ->shouldReceive('getDefinition')
  99. ->with('latte.latteFactory')
  100. ->once()
  101. ->andReturn($latteFactory);
  102. $builder
  103. ->shouldReceive('hasDefinition')
  104. ->with('nette.latte')
  105. ->once()
  106. ->andReturn(true);
  107. $builder
  108. ->shouldReceive('getDefinition')
  109. ->with('nette.latte')
  110. ->once()
  111. ->andReturn($latte);
  112. $compiler = m::mock('Nette\DI\Compiler');
  113. $compiler
  114. ->shouldReceive('getContainerBuilder')
  115. ->once()
  116. ->andReturn($builder);
  117. $this->extension->setCompiler($compiler, 'slugify');
  118. $this->extension->beforeCompile();
  119. }
  120. }