NoSuchEntityExceptionTest.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Exception;
  7. use Magento\Framework\Phrase;
  8. class NoSuchEntityExceptionTest extends \PHPUnit\Framework\TestCase
  9. {
  10. public function testConstructor()
  11. {
  12. $exception = new NoSuchEntityException();
  13. $this->assertEquals('No such entity.', $exception->getRawMessage());
  14. $this->assertEquals('No such entity.', $exception->getMessage());
  15. $this->assertEquals('No such entity.', $exception->getLogMessage());
  16. $exception = new NoSuchEntityException(
  17. new Phrase(
  18. 'No such entity with %fieldName = %fieldValue',
  19. ['fieldName' => 'field', 'fieldValue' => 'value']
  20. )
  21. );
  22. $this->assertEquals('No such entity with field = value', $exception->getMessage());
  23. $this->assertEquals('No such entity with %fieldName = %fieldValue', $exception->getRawMessage());
  24. $this->assertEquals('No such entity with field = value', $exception->getLogMessage());
  25. $exception = new NoSuchEntityException(
  26. new Phrase(
  27. 'No such entity with %fieldName = %fieldValue, %field2Name = %field2Value',
  28. [
  29. 'fieldName' => 'field1',
  30. 'fieldValue' => 'value1',
  31. 'field2Name' => 'field2',
  32. 'field2Value' => 'value2'
  33. ]
  34. )
  35. );
  36. $this->assertEquals(
  37. 'No such entity with %fieldName = %fieldValue, %field2Name = %field2Value',
  38. $exception->getRawMessage()
  39. );
  40. $this->assertEquals('No such entity with field1 = value1, field2 = value2', $exception->getMessage());
  41. $this->assertEquals('No such entity with field1 = value1, field2 = value2', $exception->getLogMessage());
  42. }
  43. }