RegexTest.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Event\Test\Unit\Observer;
  7. use \Magento\Framework\Event\Observer\Regex;
  8. /**
  9. * Class RegexTest
  10. */
  11. class RegexTest extends \PHPUnit\Framework\TestCase
  12. {
  13. /**
  14. * @var Regex
  15. */
  16. protected $regex;
  17. protected function setUp()
  18. {
  19. $this->regex = new Regex();
  20. }
  21. protected function tearDown()
  22. {
  23. $this->regex = null;
  24. }
  25. /**
  26. * @dataProvider isValidForProvider
  27. * @param string $pattern
  28. * @param string $name
  29. * @param bool $expectedResult
  30. */
  31. public function testIsValidFor($pattern, $name, $expectedResult)
  32. {
  33. $this->regex->setEventRegex($pattern);
  34. $eventMock = $this->createMock(\Magento\Framework\Event::class);
  35. $eventMock->expects($this->any())
  36. ->method('getName')
  37. ->will($this->returnValue($name));
  38. $this->assertEquals($expectedResult, $this->regex->isValidFor($eventMock));
  39. }
  40. /**
  41. * @return array
  42. */
  43. public function isValidForProvider()
  44. {
  45. return [
  46. ['~_name$~', 'event_name', true],
  47. ['~_names$~', 'event_name', false]
  48. ];
  49. }
  50. }