|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * CROSS PHPunit Utils |
| 4 | + * |
| 5 | + * @filesource |
| 6 | + * @copyright 2019 Cross Solution <https://www.cross-solution.de> |
| 7 | + * @license MIT |
| 8 | + */ |
| 9 | + |
| 10 | +declare(strict_types=1); |
| 11 | + |
| 12 | +namespace Cross\TestUtilsTest\Exception; |
| 13 | + |
| 14 | +use Cross\TestUtils\Exception\InvalidUsageException; |
| 15 | + |
| 16 | +/** |
| 17 | + * Tests for \Cross\TestUtils\Exception\TemplatedMessageExceptionTrait |
| 18 | + * |
| 19 | + * @covers \Cross\TestUtils\Exception\TemplatedMessageExceptionTrait |
| 20 | + * @author Mathias Gelhausen <gelhausen@cross-solution.de> |
| 21 | + * |
| 22 | + * @group Cross.TestUtils |
| 23 | + * @group Cross.TestUtils.Exception |
| 24 | + * @group Cross.TestUtils.Exception.TemplatedMessageExceptionTrait |
| 25 | + */ |
| 26 | +class TemplatedMessageExceptionTraitTest extends \PHPUnit_Framework_TestCase |
| 27 | +{ |
| 28 | + public function testCreateWithoutPrevious() |
| 29 | + { |
| 30 | + $target = InvalidUsageException::create('%s %s', 'value1', 'value2'); |
| 31 | + |
| 32 | + static::assertEquals('value1 value2', $target->getMessage()); |
| 33 | + } |
| 34 | + |
| 35 | + public function testCreateWithPrevious() |
| 36 | + { |
| 37 | + $ex = new \Exception; |
| 38 | + $target = InvalidUsageException::create('%s', 'value1', $ex); |
| 39 | + |
| 40 | + static::assertEquals('value1', $target->getMessage()); |
| 41 | + static::assertSame($ex, $target->getPrevious()); |
| 42 | + } |
| 43 | + |
| 44 | + public function testFromTrait() |
| 45 | + { |
| 46 | + $target = InvalidUsageException::fromTrait('TRAIT', 'CLASS', '%s', 'value1'); |
| 47 | + |
| 48 | + static::assertEquals('TRAIT: CLASS: value1', $target->getMessage()); |
| 49 | + } |
| 50 | +} |
0 commit comments