ConfigurationTest.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. /*
  3. * This file is part of the cocur/slugify package.
  4. *
  5. * (c) Enrico Stahn <enrico.stahn@gmail.com>
  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\Configuration;
  12. use Symfony\Component\Config\Definition\Exception\InvalidTypeException;
  13. use Symfony\Component\Config\Definition\Processor;
  14. use Mockery\Adapter\Phpunit\MockeryTestCase;
  15. class ConfigurationTest extends MockeryTestCase
  16. {
  17. public function testAll()
  18. {
  19. $configs = [
  20. [
  21. 'lowercase' => true,
  22. 'lowercase_after_regexp' => false,
  23. 'strip_tags' => false,
  24. 'separator' => '_',
  25. 'regexp' => 'abcd',
  26. 'rulesets' => ['burmese', 'hindi']
  27. ],
  28. ];
  29. $this->assertSame($configs[0], $this->process($configs));
  30. }
  31. public function testLowercaseOnlyAcceptsBoolean()
  32. {
  33. $this->expectException(InvalidTypeException::class);
  34. $configs = [['lowercase' => 'abc']];
  35. $this->process($configs);
  36. }
  37. public function testLowercaseAfterRegexpOnlyAcceptsBoolean()
  38. {
  39. $this->expectException(InvalidTypeException::class);
  40. $configs = [['lowercase_after_regexp' => 'abc']];
  41. $this->process($configs);
  42. }
  43. public function testStripTagsOnlyAcceptsBoolean()
  44. {
  45. $this->expectException(InvalidTypeException::class);
  46. $configs = [['strip_tags' => 'abc']];
  47. $this->process($configs);
  48. }
  49. /**
  50. * Processes an array of configurations and returns a compiled version.
  51. *
  52. * @param array $configs An array of raw configurations
  53. *
  54. * @return array A normalized array
  55. */
  56. protected function process($configs)
  57. {
  58. $processor = new Processor();
  59. return $processor->processConfiguration(new Configuration(), $configs);
  60. }
  61. }