SlugifyServiceProviderTest.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. namespace Cocur\Slugify\Tests\Bridge\League;
  3. use Cocur\Slugify\Bridge\League\SlugifyServiceProvider;
  4. use Cocur\Slugify\RuleProvider\DefaultRuleProvider;
  5. use Cocur\Slugify\RuleProvider\RuleProviderInterface;
  6. use Cocur\Slugify\SlugifyInterface;
  7. use League\Container\Container;
  8. use Mockery as m;
  9. class SlugifyServiceProviderTest extends \PHPUnit_Framework_TestCase
  10. {
  11. public function testProvidesSlugify()
  12. {
  13. $container = new Container();
  14. $container->addServiceProvider(new SlugifyServiceProvider());
  15. $slugify = $container->get(SlugifyInterface::class);
  16. $this->assertInstanceOf(SlugifyInterface::class, $slugify);
  17. $this->assertAttributeInstanceOf(DefaultRuleProvider::class, 'provider', $slugify);
  18. }
  19. public function testProvidesSlugifyAsSharedService()
  20. {
  21. $container = new Container();
  22. $container->addServiceProvider(new SlugifyServiceProvider());
  23. $slugify = $container->get(SlugifyInterface::class);
  24. $this->assertSame($slugify, $container->get(SlugifyInterface::class));
  25. }
  26. public function testProvidesSlugifyUsingSharedConfigurationOptions()
  27. {
  28. $container = new Container();
  29. $options = [
  30. 'lowercase' => false,
  31. ];
  32. $container->share('config.slugify.options', $options);
  33. $container->addServiceProvider(new SlugifyServiceProvider());
  34. /* @var SlugifyInterface $slugify */
  35. $slugify = $container->get(SlugifyInterface::class);
  36. $slug = 'Foo-Bar-Baz';
  37. $this->assertSame($slug, $slugify->slugify($slug));
  38. }
  39. public function testProvidesSlugifyUsingSharedProvider()
  40. {
  41. $container = new Container();
  42. $ruleProvider = $this->getRuleProviderMock();
  43. $container->share(RuleProviderInterface::class, $ruleProvider);
  44. $container->addServiceProvider(new SlugifyServiceProvider());
  45. $slugify = $container->get(SlugifyInterface::class);
  46. $this->assertAttributeSame($ruleProvider, 'provider', $slugify);
  47. }
  48. /**
  49. * @return m\Mock|RuleProviderInterface
  50. */
  51. private function getRuleProviderMock()
  52. {
  53. $ruleProvider = m::mock(RuleProviderInterface::class);
  54. $ruleProvider
  55. ->shouldReceive('getRules')
  56. ->withAnyArgs()
  57. ->andReturn([])
  58. ;
  59. return $ruleProvider;
  60. }
  61. }