GlobalMessageTest.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php declare(strict_types=1);
  2. namespace Inhere\ValidateTest\Validator;
  3. use Inhere\Validate\Validator\GlobalMessage;
  4. use PHPUnit\Framework\TestCase;
  5. use PHPUnit\Runner\Version;
  6. use function version_compare;
  7. /**
  8. * Class GlobalMessageTest
  9. *
  10. * @package Inhere\ValidateTest\Validator
  11. */
  12. class GlobalMessageTest extends TestCase
  13. {
  14. public function testBasic(): void
  15. {
  16. GlobalMessage::setMessages([
  17. 'key1' => 'val1',
  18. 'key2' => 'val2',
  19. 'key3' => '',
  20. ]);
  21. $this->assertNotEmpty(GlobalMessage::getMessages());
  22. $this->assertSame('val1', GlobalMessage::get('key1'));
  23. $this->assertTrue(GlobalMessage::has('key1'));
  24. $this->assertFalse(GlobalMessage::has('key3'));
  25. $needle = 'validation is not through!';
  26. if (version_compare(Version::id(), '7.0.0', '<')) {
  27. $this->assertContains($needle, GlobalMessage::getDefault());
  28. } else {
  29. $this->assertStringContainsString($needle, GlobalMessage::getDefault());
  30. }
  31. }
  32. }