-
Notifications
You must be signed in to change notification settings - Fork 132
MQE-1633 + MQE-1514 #436
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
MQE-1633 + MQE-1514 #436
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
75b6b88
MQE-1514: Failure For seeCurrentUrlEquals Action Does Not Show Actual…
KevinBKozan beec388
MQE-1514: Failure For seeCurrentUrlEquals Action Does Not Show Actual…
KevinBKozan 300619d
MQE-1633: Add API Request To Output for MFTF API Actions
KevinBKozan a32145d
Merge branch 'MQE-1514' into MQE-1633+1514
KevinBKozan fdcda9a
MQE-1514: Failure For seeCurrentUrlEquals Action Does Not Show Actual
KevinBKozan 0dd8840
MQE-1633: Add API Request To Output for MFTF API Actions
KevinBKozan fdd5ec0
MQE-1633: Add API Request To Output for MFTF API Actions
KevinBKozan a448a0f
Merge branch 'develop' into MQE-1633+1514
KevinBKozan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
dev/tests/unit/Magento/FunctionalTestFramework/Allure/AllureHelperTest.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Tests\unit\Magento\FunctionalTestingFramework\Allure; | ||
|
||
use Magento\FunctionalTestingFramework\Allure\AllureHelper; | ||
use Yandex\Allure\Adapter\Allure; | ||
use Yandex\Allure\Adapter\Event\AddAttachmentEvent; | ||
use Yandex\Allure\Adapter\Event\StepFinishedEvent; | ||
use Yandex\Allure\Adapter\Event\StepStartedEvent; | ||
use Yandex\Allure\Adapter\Model\Attachment; | ||
use AspectMock\Test as AspectMock; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class AllureHelperTest extends TestCase | ||
{ | ||
const MOCK_FILENAME = 'filename'; | ||
|
||
/** | ||
* Clear Allure Lifecycle | ||
*/ | ||
public function tearDown() | ||
{ | ||
Allure::setDefaultLifecycle(); | ||
} | ||
|
||
/** | ||
* AddAtachmentToStep should add an attachment to the current step | ||
* @throws \Yandex\Allure\Adapter\AllureException | ||
*/ | ||
public function testAddAttachmentToStep() | ||
{ | ||
$this->mockAttachmentWriteEvent(); | ||
$expectedData = "string"; | ||
$expectedCaption = "caption"; | ||
|
||
//Prepare Allure lifecycle | ||
Allure::lifecycle()->fire(new StepStartedEvent('firstStep')); | ||
|
||
//Call function | ||
AllureHelper::addAttachmentToCurrentStep($expectedData, $expectedCaption); | ||
|
||
// Assert Attachment is created as expected | ||
$step = Allure::lifecycle()->getStepStorage()->pollLast(); | ||
$expectedAttachment = new Attachment($expectedCaption, self::MOCK_FILENAME, null); | ||
$this->assertEquals($step->getAttachments()[0], $expectedAttachment); | ||
} | ||
|
||
/** | ||
* AddAttachmentToLastStep should add an attachment only to the last step | ||
* @throws \Yandex\Allure\Adapter\AllureException | ||
*/ | ||
public function testAddAttachmentToLastStep() | ||
{ | ||
$this->mockAttachmentWriteEvent(); | ||
$expectedData = "string"; | ||
$expectedCaption = "caption"; | ||
|
||
//Prepare Allure lifecycle | ||
Allure::lifecycle()->fire(new StepStartedEvent('firstStep')); | ||
Allure::lifecycle()->fire(new StepFinishedEvent('firstStep')); | ||
Allure::lifecycle()->fire(new StepStartedEvent('secondStep')); | ||
Allure::lifecycle()->fire(new StepFinishedEvent('secondStep')); | ||
|
||
//Call function | ||
AllureHelper::addAttachmentToLastStep($expectedData, $expectedCaption); | ||
|
||
//Continue Allure lifecycle | ||
Allure::lifecycle()->fire(new StepStartedEvent('thirdStep')); | ||
Allure::lifecycle()->fire(new StepFinishedEvent('thirdStep')); | ||
|
||
// Assert Attachment is created as expected on the right step | ||
$rootStep = Allure::lifecycle()->getStepStorage()->pollLast(); | ||
|
||
$firstStep = $rootStep->getSteps()[0]; | ||
$secondStep = $rootStep->getSteps()[1]; | ||
$thirdStep = $rootStep->getSteps()[2]; | ||
|
||
$expectedAttachment = new Attachment($expectedCaption, self::MOCK_FILENAME, null); | ||
$this->assertEmpty($firstStep->getAttachments()); | ||
$this->assertEquals($secondStep->getAttachments()[0], $expectedAttachment); | ||
$this->assertEmpty($thirdStep->getAttachments()); | ||
} | ||
|
||
/** | ||
* Mock file system manipulation function | ||
* @throws \Exception | ||
*/ | ||
public function mockAttachmentWriteEvent() | ||
{ | ||
AspectMock::double(AddAttachmentEvent::class, [ | ||
"getAttachmentFileName" => self::MOCK_FILENAME | ||
]); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/Magento/FunctionalTestingFramework/Allure/AllureHelper.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\FunctionalTestingFramework\Allure; | ||
|
||
use Yandex\Allure\Adapter\Allure; | ||
use Yandex\Allure\Adapter\Event\AddAttachmentEvent; | ||
|
||
class AllureHelper | ||
{ | ||
/** | ||
* Adds attachment to the current step | ||
* @param mixed $data | ||
* @param string $caption | ||
* @throws \Yandex\Allure\Adapter\AllureException | ||
* @return void | ||
*/ | ||
public static function addAttachmentToCurrentStep($data, $caption) | ||
{ | ||
Allure::lifecycle()->fire(new AddAttachmentEvent($data, $caption)); | ||
} | ||
|
||
/** | ||
* Adds Attachment to the last executed step. | ||
* Use this when adding attachments outside of an $I->doSomething() step/context. | ||
* @param mixed $data | ||
* @param string $caption | ||
* @return void | ||
*/ | ||
public static function addAttachmentToLastStep($data, $caption) | ||
{ | ||
$rootStep = Allure::lifecycle()->getStepStorage()->getLast(); | ||
$trueLastStep = array_last($rootStep->getSteps()); | ||
|
||
$attachmentEvent = new AddAttachmentEvent($data, $caption); | ||
$attachmentEvent->process($trueLastStep); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just curious about in general when to use this over the current step? I see you use this one in the curl handler, but I cant figure out why. Maybe add a bit to the phpdoc like:
This function should be used when ___blahblahblah___
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll add a comment to clear it up, the gist of it is that during a step (aka a function called in the test via
$I->doathing()
) you use current. If the framework is doign its own logic outisde a function like that, you can add artifact to the last step (which is usually a comment step)