Skip to content

Commit a25b568

Browse files
committed
Merge branch 'MQE-421' into sprint-develop
2 parents 33a862f + a053dd0 commit a25b568

File tree

15 files changed

+565
-12
lines changed

15 files changed

+565
-12
lines changed

composer.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,19 @@
1414
"require-dev": {
1515
"squizlabs/php_codesniffer": "1.5.3",
1616
"sebastian/phpcpd": "~3.0",
17-
"brainmaestro/composer-git-hooks": "^2.3"
17+
"brainmaestro/composer-git-hooks": "^2.3",
18+
"codeception/aspect-mock": "^2.0"
1819
},
1920
"autoload": {
2021
"psr-4": {
2122
"Magento\\FunctionalTestingFramework\\": ["src/Magento/FunctionalTestingFramework"]
2223
}
2324
},
25+
"autoload-dev": {
26+
"psr-4": {
27+
"tests\\unit\\Magento\\FunctionalTestingFramework\\": ["dev/tests/unit/Magento/FunctionalTestingFramework"]
28+
}
29+
},
2430
"extra": {
2531
"hooks": {
2632
"pre-push": "bin/copyright-check"

dev/tests/_bootstrap.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@
88
define('PROJECT_ROOT', dirname(dirname(__DIR__)));
99
require_once PROJECT_ROOT . '/vendor/autoload.php';
1010

11+
// Set up AspectMock
12+
$kernel = \AspectMock\Kernel::getInstance();
13+
$kernel->init([
14+
'debug' => true,
15+
'includePaths' => [PROJECT_ROOT . '/src']
16+
]);
17+
1118
// Load needed framework env params
1219
$TEST_ENVS = [
1320
'MAGENTO_BASE_URL' => 'http://baseurl:8080',
@@ -23,7 +30,6 @@
2330
// Add our test module to the whitelist
2431
putenv('MODULE_WHITELIST=Magento_TestModule');
2532

26-
2733
// Define our own set of paths for the tests
2834
defined('FW_BP') || define('FW_BP', PROJECT_ROOT);
2935

dev/tests/phpunit.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
1010
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/6.3/phpunit.xsd"
1111
convertNoticesToExceptions="false"
12-
bootstrap="_bootstrap.php">
12+
bootstrap="_bootstrap.php"
13+
backupGlobals="false">
1314
<testsuites>
1415
<testsuite name="verification">
1516
<directory>verification</directory>
@@ -27,4 +28,4 @@
2728
<directory suffix=".php">../../src/Magento/FunctionalTestingFramework/Util</directory>
2829
</whitelist>
2930
</filter>
30-
</phpunit>
31+
</phpunit>
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace tests\unit\Magento\FunctionalTestFramework\DataGenerator\Handlers;
8+
9+
use AspectMock\Test as AspectMock;
10+
use Magento\FunctionalTestingFramework\DataGenerator\Handlers\DataObjectHandler;
11+
use Magento\FunctionalTestingFramework\DataGenerator\Objects\EntityDataObject;
12+
use Magento\FunctionalTestingFramework\DataGenerator\Parsers\DataProfileSchemaParser;
13+
use Magento\FunctionalTestingFramework\ObjectManager;
14+
use Magento\FunctionalTestingFramework\ObjectManagerFactory;
15+
use PHPUnit\Framework\TestCase;
16+
17+
/**
18+
* Class DataObjectHandlerTest
19+
*/
20+
class DataObjectHandlerTest extends TestCase
21+
{
22+
// All tests share this array, feel free to add but be careful modifying or removing
23+
const PARSER_OUTPUT = [
24+
'entity' => [
25+
'EntityOne' => [
26+
'type' => 'testType',
27+
'data' => [
28+
0 => [
29+
'key' => 'testKey',
30+
'value' => 'testValue'
31+
]
32+
]
33+
]
34+
]
35+
];
36+
37+
/**
38+
* Set up everything required to mock DataObjectHander::getInstance()
39+
* The first call to getInstance() uses these mocks to emulate the parser, initializing internal state
40+
* according to the PARSER_OUTPUT value
41+
*/
42+
public static function setUpBeforeClass()
43+
{
44+
$mockDataProfileSchemaParser = AspectMock::double(DataProfileSchemaParser::class, [
45+
'readDataProfiles' => self::PARSER_OUTPUT
46+
])->make();
47+
48+
$mockObjectManager = AspectMock::double(ObjectManager::class, [
49+
'create' => $mockDataProfileSchemaParser
50+
])->make();
51+
52+
AspectMock::double(ObjectManagerFactory::class, [
53+
'getObjectManager' => $mockObjectManager
54+
]);
55+
}
56+
57+
/**
58+
* getAllObjects should contain the expected data object
59+
*/
60+
public function testGetAllObjects()
61+
{
62+
// Call the method under test
63+
64+
$actual = DataObjectHandler::getInstance()->getAllObjects();
65+
66+
// Assert
67+
68+
$expected = new EntityDataObject('EntityOne', 'testType', ['testkey' => 'testValue'], [], null, []);
69+
$this->assertArrayHasKey('EntityOne', $actual);
70+
$this->assertEquals($expected, $actual['EntityOne']);
71+
}
72+
73+
/**
74+
* getObject should return the expected data object if it exists
75+
*/
76+
public function testGetObject()
77+
{
78+
// Call the method under test
79+
80+
$actual = DataObjectHandler::getInstance()->getObject('EntityOne');
81+
82+
// Assert
83+
84+
$expected = new EntityDataObject('EntityOne', 'testType', ['testkey' => 'testValue'], [], null, []);
85+
$this->assertEquals($expected, $actual);
86+
}
87+
88+
/**
89+
* getObject should return null if the data object does not exist
90+
*/
91+
public function testGetObjectNull()
92+
{
93+
$actual = DataObjectHandler::getInstance()->getObject('h953u789h0g73t521'); // doesnt exist
94+
$this->assertNull($actual);
95+
}
96+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace tests\unit\Magento\FunctionalTestFramework\DataGenerator\Handlers;
8+
9+
use PHPUnit\Framework\TestCase;
10+
11+
/**
12+
* Class OperationDefinitionObjectHandlerTest
13+
*/
14+
class OperationDefinitionObjectHandlerTest extends TestCase
15+
{
16+
public function testTodo()
17+
{
18+
$this->markTestIncomplete('TODO');
19+
}
20+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace tests\unit\Magento\FunctionalTestFramework\DataGenerator\Objects;
8+
9+
use PHPUnit\Framework\TestCase;
10+
11+
/**
12+
* Class EntityDataObjectTest
13+
*/
14+
class EntityDataObjectTest extends TestCase
15+
{
16+
public function testTodo()
17+
{
18+
$this->markTestIncomplete('TODO');
19+
}
20+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace tests\unit\Magento\FunctionalTestFramework\Page\Handlers;
8+
9+
use PHPUnit\Framework\TestCase;
10+
11+
class PageObjectHandlerTest extends TestCase
12+
{
13+
public function testTodo()
14+
{
15+
$this->markTestIncomplete('TODO');
16+
}
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace tests\unit\Magento\FunctionalTestFramework\Page\Handlers;
8+
9+
use PHPUnit\Framework\TestCase;
10+
11+
class SectionObjectHandlerTest extends TestCase
12+
{
13+
public function testTodo()
14+
{
15+
$this->markTestIncomplete('TODO');
16+
}
17+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace tests\unit\Magento\FunctionalTestFramework\Page\Objects;
8+
9+
use Magento\FunctionalTestingFramework\Exceptions\XmlException;
10+
use Magento\FunctionalTestingFramework\Page\Objects\ElementObject;
11+
use PHPUnit\Framework\TestCase;
12+
13+
/**
14+
* Class ElementObjectTest
15+
*/
16+
class ElementObjectTest extends TestCase
17+
{
18+
/**
19+
* Timeout should be null when instantiated with '-'
20+
*/
21+
public function testTimeoutDefault()
22+
{
23+
$element = new ElementObject('name', 'type', 'selector', null, '-', false);
24+
$this->assertNull($element->getTimeout());
25+
}
26+
27+
/**
28+
* Timeout should be cast to an integer
29+
*/
30+
public function testTimeoutNotNull()
31+
{
32+
$element = new ElementObject('name', 'type', 'selector', null, '15', false);
33+
$timeout = $element->getTimeout();
34+
$this->assertEquals(15, $timeout);
35+
$this->assertInternalType('int', $timeout);
36+
}
37+
38+
/**
39+
* Timeout should be 0 when a string is the value
40+
*/
41+
public function testTimeoutCastFromString()
42+
{
43+
$element = new ElementObject('name', 'type', 'selector', null, 'helloString', true);
44+
$timeout = $element->getTimeout();
45+
$this->assertEquals(0, $timeout);
46+
$this->assertInternalType('int', $timeout);
47+
}
48+
49+
/**
50+
* An exception should be thrown if both a selector and locatorFunction are passed
51+
*/
52+
public function testBothSelectorAndLocatorFunction()
53+
{
54+
$this->expectException(XmlException::class);
55+
new ElementObject('name', 'type', 'selector', 'cantHaveThisAndSelector', '-', false);
56+
}
57+
58+
/**
59+
* An exception should be thrown if neither a selector nor locatorFunction are passed
60+
*/
61+
public function testNeitherSelectorNorLocatorFunction()
62+
{
63+
$this->expectException(XmlException::class);
64+
new ElementObject('name', 'type', null, null, '-', false);
65+
}
66+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace tests\unit\Magento\FunctionalTestFramework\Page\Objects;
8+
9+
use Magento\FunctionalTestingFramework\Page\Objects\PageObject;
10+
use PHPUnit\Framework\TestCase;
11+
12+
/**
13+
* Class PageObjectTest
14+
*/
15+
class PageObjectTest extends TestCase
16+
{
17+
/**
18+
* Assert that the page object has a section
19+
*/
20+
public function testHasSection()
21+
{
22+
$page = new PageObject('name', 'urlPath', 'module', ['section1', 'section2'], false);
23+
$this->assertTrue($page->hasSection('section1'));
24+
}
25+
26+
/**
27+
* Assert that the page object doesn't have a section
28+
*/
29+
public function testDoesntHaveSection()
30+
{
31+
$page = new PageObject('name', 'urlPath', 'module', ['section1', 'section2'], false);
32+
$this->assertFalse($page->hasSection('section3'));
33+
}
34+
}

0 commit comments

Comments
 (0)