Skip to content

Commit a1ba0b9

Browse files
authored
Merge pull request #292 from magento-gl/codeception-allure-qameta_
ACQE-4694 : Codeception and Alure codeception upgrade and fixes
2 parents 3ce1e08 + 4cc11fa commit a1ba0b9

File tree

17 files changed

+1462
-939
lines changed

17 files changed

+1462
-939
lines changed

composer.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@
1616
"ext-intl": "*",
1717
"ext-json": "*",
1818
"ext-openssl": "*",
19-
"allure-framework/allure-codeception": "^1.5",
19+
"allure-framework/allure-codeception": "^2.1",
2020
"allure-framework/allure-phpunit": "^2",
2121
"aws/aws-sdk-php": "^3.132",
22-
"codeception/codeception": "^4.1",
23-
"codeception/module-asserts": "^1.1",
24-
"codeception/module-sequence": "^1.0",
25-
"codeception/module-webdriver": "^1.0",
22+
"codeception/codeception": "^5.0",
23+
"codeception/module-asserts": "^3.0",
24+
"codeception/module-sequence": "^3.0",
25+
"codeception/module-webdriver": "^3.0",
2626
"composer/composer": "^1.9 || ^2.0, !=2.2.16",
2727
"csharpru/vault-php": "^4.2.1",
2828
"guzzlehttp/guzzle": "^7.3.0",
@@ -47,7 +47,7 @@
4747
"codacy/coverage": "^1.4",
4848
"php-coveralls/php-coveralls": "^1.0||^2.2",
4949
"phpmd/phpmd": "^2.8.0",
50-
"phpunit/phpunit": "^9.0",
50+
"phpunit/phpunit": "<=9.5.20",
5151
"sebastian/phpcpd": "~6.0.0",
5252
"squizlabs/php_codesniffer": "~3.6.0"
5353
},

composer.lock

Lines changed: 955 additions & 678 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dev/tests/unit/Magento/FunctionalTestFramework/Allure/AllureHelperTest.php

Lines changed: 99 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -8,158 +8,129 @@
88
namespace tests\unit\Magento\FunctionalTestFramework\Allure;
99

1010
use Magento\FunctionalTestingFramework\Allure\AllureHelper;
11-
use Magento\FunctionalTestingFramework\Allure\Event\AddUniqueAttachmentEvent;
12-
use Magento\FunctionalTestingFramework\ObjectManager;
1311
use PHPUnit\Framework\TestCase;
14-
use ReflectionProperty;
15-
use Yandex\Allure\Adapter\Allure;
16-
use Yandex\Allure\Adapter\AllureException;
17-
use Yandex\Allure\Adapter\Event\StepFinishedEvent;
18-
use Yandex\Allure\Adapter\Event\StepStartedEvent;
19-
use Yandex\Allure\Adapter\Model\Attachment;
12+
use Qameta\Allure\Allure;
13+
use Qameta\Allure\Io\DataSourceFactory;
14+
use Qameta\Allure\Model\AttachmentResult;
15+
use Qameta\Allure\Model\ResultFactoryInterface;
16+
use Qameta\Allure\Setup\LifecycleBuilderInterface;
17+
use const STDOUT;
2018

19+
/**
20+
* @covers \Qameta\Allure\Allure
21+
*/
2122
class AllureHelperTest extends TestCase
2223
{
23-
private const MOCK_FILENAME = 'filename';
24-
25-
/**
26-
* The AddAttachmentToStep should add an attachment to the current step.
27-
*
28-
* @return void
29-
* @throws AllureException
30-
*/
31-
public function testAddAttachmentToStep(): void
24+
public function setUp(): void
3225
{
33-
$expectedData = 'string';
34-
$expectedCaption = 'caption';
35-
$this->mockAttachmentWriteEvent($expectedData, $expectedCaption);
36-
37-
//Prepare Allure lifecycle
38-
Allure::lifecycle()->fire(new StepStartedEvent('firstStep'));
39-
40-
//Call function
41-
AllureHelper::addAttachmentToCurrentStep($expectedData, $expectedCaption);
42-
43-
// Assert Attachment is created as expected
44-
$step = Allure::lifecycle()->getStepStorage()->pollLast();
45-
$expectedAttachment = new Attachment($expectedCaption, self::MOCK_FILENAME, null);
46-
$this->assertEquals($step->getAttachments()[0], $expectedAttachment);
26+
Allure::reset();
4727
}
4828

4929
/**
50-
* The AddAttachmentToLastStep should add an attachment only to the last step.
51-
*
52-
* @return void
53-
* @throws AllureException
30+
* @dataProvider providerAttachmentProperties
5431
*/
55-
public function testAddAttachmentToLastStep(): void
56-
{
57-
$expectedData = 'string';
58-
$expectedCaption = 'caption';
59-
$this->mockAttachmentWriteEvent($expectedData, $expectedCaption);
60-
61-
//Prepare Allure lifecycle
62-
Allure::lifecycle()->fire(new StepStartedEvent('firstStep'));
63-
Allure::lifecycle()->fire(new StepFinishedEvent('firstStep'));
64-
Allure::lifecycle()->fire(new StepStartedEvent('secondStep'));
65-
Allure::lifecycle()->fire(new StepFinishedEvent('secondStep'));
66-
67-
//Call function
68-
AllureHelper::addAttachmentToLastStep($expectedData, $expectedCaption);
69-
70-
//Continue Allure lifecycle
71-
Allure::lifecycle()->fire(new StepStartedEvent('thirdStep'));
72-
Allure::lifecycle()->fire(new StepFinishedEvent('thirdStep'));
73-
74-
// Assert Attachment is created as expected on the right step
75-
$rootStep = Allure::lifecycle()->getStepStorage()->pollLast();
76-
77-
$firstStep = $rootStep->getSteps()[0];
78-
$secondStep = $rootStep->getSteps()[1];
79-
$thirdStep = $rootStep->getSteps()[2];
80-
81-
$expectedAttachment = new Attachment($expectedCaption, self::MOCK_FILENAME, null);
82-
$this->assertEmpty($firstStep->getAttachments());
83-
$this->assertEquals($secondStep->getAttachments()[0], $expectedAttachment);
84-
$this->assertEmpty($thirdStep->getAttachments());
32+
public function testDoAddAttachmentMethod(
33+
string $name,
34+
$type,
35+
?string $fileExtension,
36+
): void {
37+
$attachment = new AttachmentResult('a');
38+
Allure::setLifecycleBuilder(
39+
$this->createLifecycleBuilder($this->createResultFactoryWithAttachment($attachment)),
40+
);
41+
42+
AllureHelper::doAddAttachment(
43+
DataSourceFactory::fromFile('test'),
44+
'nameOfTheFile',
45+
'typeOfTheFile',
46+
$fileExtension
47+
);
48+
self::assertSame('nameOfTheFile', $attachment->getName());
49+
self::assertSame('typeOfTheFile', $attachment->getType());
8550
}
8651

8752
/**
88-
* The AddAttachment actions should have files with different attachment names.
89-
*
90-
* @return void
91-
* @throws AllureException
53+
* @dataProvider providerAttachmentProperties
9254
*/
93-
public function testAddAttachmentUniqueName(): void
94-
{
95-
$expectedData = 'string';
96-
$expectedCaption = 'caption';
97-
98-
//Prepare Allure lifecycle
99-
Allure::lifecycle()->fire(new StepStartedEvent('firstStep'));
100-
101-
//Call function twice
102-
AllureHelper::addAttachmentToCurrentStep($expectedData, $expectedCaption);
103-
AllureHelper::addAttachmentToCurrentStep($expectedData, $expectedCaption);
104-
105-
// Assert file names for both attachments are not the same.
106-
$step = Allure::lifecycle()->getStepStorage()->pollLast();
107-
$attachmentOne = $step->getAttachments()[0]->getSource();
108-
$attachmentTwo = $step->getAttachments()[1]->getSource();
109-
$this->assertNotEquals($attachmentOne, $attachmentTwo);
55+
public function testAddAttachmentToStep(
56+
string $name,
57+
?string $type,
58+
?string $fileExtension,
59+
): void {
60+
$attachment = new AttachmentResult('a');
61+
Allure::setLifecycleBuilder(
62+
$this->createLifecycleBuilder($this->createResultFactoryWithAttachment($attachment)),
63+
);
64+
65+
Allure::attachment($name, 'nameOfTheFile', $type, $fileExtension);
66+
self::assertSame($name, $attachment->getName());
67+
self::assertSame($type, $attachment->getType());
68+
self::assertSame($fileExtension, $attachment->getFileExtension());
11069
}
11170

11271
/**
113-
* Clear Allure Lifecycle.
114-
*
115-
* @return void
72+
* @dataProvider providerAttachmentProperties
11673
*/
117-
protected function tearDown(): void
118-
{
119-
Allure::setDefaultLifecycle();
120-
121-
$objectManagerProperty = new ReflectionProperty(ObjectManager::class, 'instance');
122-
$objectManagerProperty->setAccessible(true);
123-
$objectManagerProperty->setValue(null);
74+
public function testAddAttachmentFileToStep(
75+
string $name,
76+
?string $type,
77+
?string $fileExtension,
78+
): void {
79+
$attachment = new AttachmentResult('a');
80+
Allure::setLifecycleBuilder(
81+
$this->createLifecycleBuilder($this->createResultFactoryWithAttachment($attachment)),
82+
);
83+
84+
Allure::attachmentFile($name, 'b', $type, '.html');
85+
self::assertSame('c', $attachment->getName());
86+
self::assertSame('.html', $attachment->getFileExtension());
12487
}
12588

12689
/**
127-
* Mock entire attachment writing mechanisms.
128-
*
129-
* @param string $filePathOrContents
130-
* @param string $caption
131-
*
132-
* @return void
90+
* @return iterable<string, array{string, string|null, string|null}>
13391
*/
134-
private function mockAttachmentWriteEvent(string $filePathOrContents, string $caption): void
92+
public static function providerAttachmentProperties(): iterable
13593
{
136-
$mockInstance = $this->getMockBuilder(AddUniqueAttachmentEvent::class)
137-
->setConstructorArgs([$filePathOrContents, $caption])
138-
->disallowMockingUnknownTypes()
139-
->onlyMethods(['getAttachmentFileName'])
140-
->getMock();
141-
142-
$mockInstance
143-
->method('getAttachmentFileName')
144-
->willReturn(self::MOCK_FILENAME);
94+
return [
95+
'Only name' => ['c', null, null],
96+
'Name and type' => ['c', 'd', null],
97+
'Name and file extension' => ['c', null, 'd'],
98+
'Name, type and file extension' => ['c', 'd', 'e'],
99+
];
100+
}
145101

146-
$objectManagerMockInstance = $this->createMock(ObjectManager::class);
147-
$objectManagerMockInstance
148-
->method('create')
149-
->will(
150-
$this->returnCallback(
151-
function (string $class) use ($mockInstance) {
152-
if ($class === AddUniqueAttachmentEvent::class) {
153-
return $mockInstance;
154-
}
102+
private function createResultFactoryWithAttachment(AttachmentResult $attachment): ResultFactoryInterface
103+
{
104+
$resultFactory = $this->createStub(ResultFactoryInterface::class);
105+
$resultFactory
106+
->method('createAttachment')
107+
->willReturn($attachment);
155108

156-
return null;
157-
}
158-
)
159-
);
109+
return $resultFactory;
110+
}
160111

161-
$objectManagerProperty = new ReflectionProperty(ObjectManager::class, 'instance');
162-
$objectManagerProperty->setAccessible(true);
163-
$objectManagerProperty->setValue($objectManagerMockInstance, $objectManagerMockInstance);
112+
private function createLifecycleBuilder(
113+
?ResultFactoryInterface $resultFactory = null,
114+
?AllureLifecycleInterface $lifecycle = null,
115+
?StatusDetectorInterface $statusDetector = null,
116+
): LifecycleBuilderInterface {
117+
$builder = $this->createStub(LifecycleBuilderInterface::class);
118+
if (isset($resultFactory)) {
119+
$builder
120+
->method('getResultFactory')
121+
->willReturn($resultFactory);
122+
}
123+
if (isset($lifecycle)) {
124+
$builder
125+
->method('createLifecycle')
126+
->willReturn($lifecycle);
127+
}
128+
if (isset($statusDetector)) {
129+
$builder
130+
->method('getStatusDetector')
131+
->willReturn($statusDetector);
132+
}
133+
134+
return $builder;
164135
}
165136
}

dev/tests/verification/Resources/ActionsInDifferentModulesSuite.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,15 +120,15 @@ class ActionsInDifferentModulesSuite extends \Codeception\GroupObject
120120
//Access private TestResultObject to find stack and if there are any errors (as opposed to failures)
121121
$testResultObject = call_user_func(\Closure::bind(
122122
function () use ($cest) {
123-
return $cest->getTestResultObject();
123+
return $cest->getResultAggregator();
124124
},
125125
$cest
126126
));
127127
$errors = $testResultObject->errors();
128128

129129
if (!empty($errors)) {
130130
foreach ($errors as $error) {
131-
if ($error->failedTest()->getTestMethod() == $cest->getName()) {
131+
if ($error->getTest()->getTestMethod() == $cest->getName()) {
132132
// Do not attempt to run _after if failure was in the _after block
133133
// Try to run _after but catch exceptions to prevent them from overwriting original failure.
134134
print("LAST TEST IN SUITE FAILED, TEST AFTER MAY NOT BE SUCCESSFUL\n");

dev/tests/verification/Resources/functionalSuiteHooks.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,15 +122,15 @@ class functionalSuiteHooks extends \Codeception\GroupObject
122122
//Access private TestResultObject to find stack and if there are any errors (as opposed to failures)
123123
$testResultObject = call_user_func(\Closure::bind(
124124
function () use ($cest) {
125-
return $cest->getTestResultObject();
125+
return $cest->getResultAggregator();
126126
},
127127
$cest
128128
));
129129
$errors = $testResultObject->errors();
130130

131131
if (!empty($errors)) {
132132
foreach ($errors as $error) {
133-
if ($error->failedTest()->getTestMethod() == $cest->getName()) {
133+
if ($error->getTest()->getTestMethod() == $cest->getName()) {
134134
// Do not attempt to run _after if failure was in the _after block
135135
// Try to run _after but catch exceptions to prevent them from overwriting original failure.
136136
print("LAST TEST IN SUITE FAILED, TEST AFTER MAY NOT BE SUCCESSFUL\n");

dev/tests/verification/Resources/functionalSuiteWithComments.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,15 @@ class functionalSuiteWithComments extends \Codeception\GroupObject
106106
//Access private TestResultObject to find stack and if there are any errors (as opposed to failures)
107107
$testResultObject = call_user_func(\Closure::bind(
108108
function () use ($cest) {
109-
return $cest->getTestResultObject();
109+
return $cest->getResultAggregator();
110110
},
111111
$cest
112112
));
113113
$errors = $testResultObject->errors();
114114

115115
if (!empty($errors)) {
116116
foreach ($errors as $error) {
117-
if ($error->failedTest()->getTestMethod() == $cest->getName()) {
117+
if ($error->getTest()->getTestMethod() == $cest->getName()) {
118118
// Do not attempt to run _after if failure was in the _after block
119119
// Try to run _after but catch exceptions to prevent them from overwriting original failure.
120120
print("LAST TEST IN SUITE FAILED, TEST AFTER MAY NOT BE SUCCESSFUL\n");

etc/config/codeception.dist.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ paths:
77
data: tests/_data
88
support: src/Magento/FunctionalTestingFramework
99
envs: etc/_envs
10+
output: tests/_output
1011
settings:
1112
silent: true
1213
colors: true
@@ -15,9 +16,9 @@ extensions:
1516
enabled:
1617
- Magento\FunctionalTestingFramework\Codeception\Subscriber\Console
1718
- Magento\FunctionalTestingFramework\Extension\TestContextExtension
18-
- Magento\FunctionalTestingFramework\Allure\Adapter\MagentoAllureAdapter
19+
- Qameta\Allure\Codeception\AllureCodeception
1920
config:
20-
Magento\FunctionalTestingFramework\Allure\Adapter\MagentoAllureAdapter:
21+
Qameta\Allure\Codeception\AllureCodeception:
2122
deletePreviousResults: false
2223
outputDirectory: allure-results
2324
ignoredAnnotations:
@@ -27,4 +28,4 @@ extensions:
2728
Magento\FunctionalTestingFramework\Extension\TestContextExtension:
2829
driver: \Magento\FunctionalTestingFramework\Module\MagentoWebDriver
2930
params:
30-
- .env
31+
- .env

etc/config/functional.suite.dist.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# Perform tests in browser using the WebDriver or PhpBrowser.
88
# If you need both WebDriver and PHPBrowser tests - create a separate suite.
99

10-
class_name: AcceptanceTester
10+
actor: AcceptanceTester
1111
namespace: Magento\FunctionalTestingFramework
1212
modules:
1313
enabled:
@@ -27,9 +27,9 @@ modules:
2727
window_size: 1280x1024
2828
username: "%MAGENTO_ADMIN_USERNAME%"
2929
password: "%MAGENTO_ADMIN_PASSWORD%"
30-
pageload_timeout: "%WAIT_TIMEOUT%"
31-
request_timeout: "%WAIT_TIMEOUT%"
32-
connection_timeout: "%WAIT_TIMEOUT%"
30+
pageload_timeout: "30"
31+
request_timeout: "30"
32+
connection_timeout: "30"
3333
host: "%SELENIUM_HOST%"
3434
port: "%SELENIUM_PORT%"
3535
protocol: "%SELENIUM_PROTOCOL%"

0 commit comments

Comments
 (0)