|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Yandex\Allure\Codeception; |
| 6 | + |
| 7 | +use Codeception\Lib\ModuleContainer; |
| 8 | +use Codeception\Scenario; |
| 9 | +use Codeception\Step\Assertion; |
| 10 | +use Codeception\Step\Comment; |
| 11 | +use Codeception\Step\Meta; |
| 12 | +use Codeception\Step\TryTo; |
| 13 | +use Codeception\Test\Unit; |
| 14 | +use Exception; |
| 15 | +use PHPUnit\Framework\Assert; |
| 16 | + |
| 17 | +class StepsTest extends Unit |
| 18 | +{ |
| 19 | + |
| 20 | + public function testNoStepsSuccess(): void |
| 21 | + { |
| 22 | + $this->expectNotToPerformAssertions(); |
| 23 | + } |
| 24 | + |
| 25 | + /** |
| 26 | + * @throws Exception |
| 27 | + */ |
| 28 | + public function testNoStepsError(): void |
| 29 | + { |
| 30 | + throw new Exception('Error'); |
| 31 | + } |
| 32 | + |
| 33 | + public function testNoStepsFailure(): void |
| 34 | + { |
| 35 | + self::fail('Failure'); |
| 36 | + } |
| 37 | + |
| 38 | + public function testNoStepsSkipped(): void |
| 39 | + { |
| 40 | + self::markTestSkipped('Skipped'); |
| 41 | + } |
| 42 | + |
| 43 | + public function testSingleSuccessfulStepWithTitle(): void |
| 44 | + { |
| 45 | + $this->expectNotToPerformAssertions(); |
| 46 | + $scenario = new Scenario($this); |
| 47 | + $scenario->runStep(new Comment('Step 1 name')); |
| 48 | + } |
| 49 | + |
| 50 | + public function testTwoSuccessfulSteps(): void |
| 51 | + { |
| 52 | + $this->expectNotToPerformAssertions(); |
| 53 | + |
| 54 | + $scenario = new Scenario($this); |
| 55 | + $scenario->runStep(new Comment('Step 1 name')); |
| 56 | + $scenario->runStep(new Comment('Step 2 name')); |
| 57 | + } |
| 58 | + |
| 59 | + public function testTwoStepsFirstFails(): void |
| 60 | + { |
| 61 | + $this->expectNotToPerformAssertions(); |
| 62 | + |
| 63 | + $scenario = new Scenario($this); |
| 64 | + $scenario->runStep($this->createFailingStep('Step 1 name', 'Failure')); |
| 65 | + $scenario->runStep(new Comment('Step 2 name')); |
| 66 | + } |
| 67 | + |
| 68 | + public function testTwoStepsSecondFails(): void |
| 69 | + { |
| 70 | + $this->expectNotToPerformAssertions(); |
| 71 | + |
| 72 | + $scenario = new Scenario($this); |
| 73 | + $scenario->runStep(new Comment('Step 1 name')); |
| 74 | + $scenario->runStep($this->createFailingStep('Step 2 name', 'Failure')); |
| 75 | + } |
| 76 | + |
| 77 | + private function createFailingStep(string $name, string $failure): \Codeception\Step |
| 78 | + { |
| 79 | + return new class ($failure, $name) extends Meta { |
| 80 | + |
| 81 | + private $failure; |
| 82 | + |
| 83 | + public function __construct(string $failure, $action, array $arguments = []) |
| 84 | + { |
| 85 | + parent::__construct($action, $arguments); |
| 86 | + $this->failure = $failure; |
| 87 | + } |
| 88 | + |
| 89 | + public function run(ModuleContainer $container = null) |
| 90 | + { |
| 91 | + $this->setFailed(true); |
| 92 | + Assert::fail($this->failure); |
| 93 | + } |
| 94 | + }; |
| 95 | + } |
| 96 | +} |
0 commit comments