SlugifyServiceTest.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. namespace Cocur\Slugify\Tests\Bridge\ZF2;
  3. use Cocur\Slugify\Bridge\ZF2\Module;
  4. use Cocur\Slugify\Bridge\ZF2\SlugifyService;
  5. use Zend\ServiceManager\ServiceManager;
  6. use Mockery\Adapter\Phpunit\MockeryTestCase;
  7. /**
  8. * Class SlugifyServiceTest
  9. * @package cocur/slugify
  10. * @subpackage bridge
  11. * @license http://www.opensource.org/licenses/MIT The MIT License
  12. */
  13. class SlugifyServiceTest extends MockeryTestCase
  14. {
  15. /**
  16. * @var SlugifyService
  17. */
  18. private $slugifyService;
  19. protected function setUp()
  20. {
  21. $this->slugifyService = new SlugifyService();
  22. }
  23. /**
  24. *
  25. * @covers Cocur\Slugify\Bridge\ZF2\SlugifyService::__invoke()
  26. */
  27. public function testInvokeWithoutCustomConfig()
  28. {
  29. $sm = $this->createServiceManagerMock();
  30. $slugify = call_user_func($this->slugifyService, $sm);
  31. $this->assertInstanceOf('Cocur\Slugify\Slugify', $slugify);
  32. // Make sure reg exp is default one
  33. $actual = 'Hello My Friend.zip';
  34. $expected = 'hello-my-friend-zip';
  35. $this->assertEquals($expected, $slugify->slugify($actual));
  36. }
  37. /**
  38. *
  39. * @covers Cocur\Slugify\Bridge\ZF2\SlugifyService::__invoke()
  40. */
  41. public function testInvokeWithCustomConfig()
  42. {
  43. $sm = $this->createServiceManagerMock([
  44. Module::CONFIG_KEY => [
  45. 'options' => ['regexp' => '/([^a-z0-9.]|-)+/']
  46. ]
  47. ]);
  48. $slugify = call_user_func($this->slugifyService, $sm);
  49. $this->assertInstanceOf('Cocur\Slugify\Slugify', $slugify);
  50. // Make sure reg exp is the one provided and dots are kept
  51. $actual = 'Hello My Friend.zip';
  52. $expected = 'hello-my-friend.zip';
  53. $this->assertEquals($expected, $slugify->slugify($actual));
  54. }
  55. protected function createServiceManagerMock(array $config = [])
  56. {
  57. $sm = new ServiceManager();
  58. $sm->setService('Config', $config);
  59. return $sm;
  60. }
  61. }