init
This commit is contained in:
48
vendor/codeception/base/tests/unit/Codeception/Lib/Console/ColorizerTest.php
vendored
Normal file
48
vendor/codeception/base/tests/unit/Codeception/Lib/Console/ColorizerTest.php
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
namespace Codeception\Lib\Console;
|
||||
|
||||
use Codeception\Test\Unit;
|
||||
|
||||
/**
|
||||
* ColorizerTest
|
||||
**/
|
||||
class ColorizerTest extends Unit
|
||||
{
|
||||
/**
|
||||
* @var Colorizer
|
||||
*/
|
||||
protected $colorizer;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->colorizer = new Colorizer();
|
||||
}
|
||||
|
||||
public function testItAddFormatToDiffMessage()
|
||||
{
|
||||
$toColorizeInput = <<<PLAIN
|
||||
foo
|
||||
bar
|
||||
+ actual line
|
||||
- expected line
|
||||
bar
|
||||
PLAIN;
|
||||
|
||||
$expectedColorized = <<<COLORED
|
||||
foo
|
||||
bar
|
||||
<info>+ actual line</info>
|
||||
<comment>- expected line</comment>
|
||||
bar
|
||||
COLORED;
|
||||
|
||||
$actual = $this->colorizer->colorize($toColorizeInput);
|
||||
|
||||
|
||||
$this->assertEquals($expectedColorized, $actual, 'it should add the format tags');
|
||||
}
|
||||
}
|
||||
54
vendor/codeception/base/tests/unit/Codeception/Lib/Console/DiffFactoryTest.php
vendored
Normal file
54
vendor/codeception/base/tests/unit/Codeception/Lib/Console/DiffFactoryTest.php
vendored
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
namespace Codeception\Lib\Console;
|
||||
|
||||
use SebastianBergmann\Comparator\ComparisonFailure;
|
||||
|
||||
/**
|
||||
* DiffFactoryTest
|
||||
**/
|
||||
class DiffFactoryTest extends \Codeception\Test\Unit
|
||||
{
|
||||
/**
|
||||
* @var DiffFactory
|
||||
*/
|
||||
protected $diffFactory;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->diffFactory = new DiffFactory();
|
||||
}
|
||||
|
||||
public function testItCreatesMessageForComparisonFailure()
|
||||
{
|
||||
$expectedDiff = $this->getExpectedDiff();
|
||||
$failure = $this->createFailure();
|
||||
$message = $this->diffFactory->createDiff($failure);
|
||||
|
||||
$this->assertEquals($expectedDiff, (string) $message, 'The diff should be generated.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ComparisonFailure
|
||||
*/
|
||||
protected function createFailure()
|
||||
{
|
||||
$expected = "a\nb";
|
||||
$actual = "a\nc";
|
||||
|
||||
return new ComparisonFailure($expected, $actual, $expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function getExpectedDiff()
|
||||
{
|
||||
$expectedDiff = <<<TXT
|
||||
@@ @@
|
||||
a
|
||||
-b
|
||||
+c
|
||||
TXT;
|
||||
return $expectedDiff . "\n";
|
||||
}
|
||||
}
|
||||
33
vendor/codeception/base/tests/unit/Codeception/Lib/Console/MessageTest.php
vendored
Normal file
33
vendor/codeception/base/tests/unit/Codeception/Lib/Console/MessageTest.php
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
namespace Codeception\Lib\Console;
|
||||
|
||||
class MessageTest extends \Codeception\Test\Unit
|
||||
{
|
||||
|
||||
// tests
|
||||
public function testCut()
|
||||
{
|
||||
$message = new Message('very long text');
|
||||
$this->assertEquals('very long ', $message->cut(10)->getMessage());
|
||||
|
||||
$message = new Message('очень длинный текст');
|
||||
$this->assertEquals('очень длин', $message->cut(10)->getMessage());
|
||||
}
|
||||
|
||||
//test message cutting
|
||||
// @codingStandardsIgnoreStart
|
||||
public function testVeryLongTestNameVeryLongTestNameVeryLongTestNameVeryLongTestNameVeryLongTestNameVeryLongTestNameVeryLongTestName()
|
||||
{
|
||||
// @codingStandardsIgnoreEnd
|
||||
}
|
||||
|
||||
// test multibyte message width
|
||||
public function testWidth()
|
||||
{
|
||||
$message = new Message('message example');
|
||||
$this->assertEquals('message example ', $message->width(30)->getMessage());
|
||||
|
||||
$message = new Message('пример текста');
|
||||
$this->assertEquals('пример текста ', $message->width(30)->getMessage());
|
||||
}
|
||||
}
|
||||
50
vendor/codeception/base/tests/unit/Codeception/Lib/DiTest.php
vendored
Normal file
50
vendor/codeception/base/tests/unit/Codeception/Lib/DiTest.php
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
namespace Codeception\Lib;
|
||||
|
||||
class DiTest extends \Codeception\Test\Unit
|
||||
{
|
||||
/**
|
||||
* @var Di
|
||||
*/
|
||||
protected $di;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->di = new Di();
|
||||
}
|
||||
|
||||
protected function injectionShouldFail($msg = '')
|
||||
{
|
||||
$this->setExpectedException('Codeception\Exception\InjectionException', $msg);
|
||||
}
|
||||
|
||||
public function testFailDependenciesCyclic()
|
||||
{
|
||||
require_once codecept_data_dir().'FailDependenciesCyclic.php';
|
||||
$this->injectionShouldFail(
|
||||
'Failed to resolve cyclic dependencies for class \'FailDependenciesCyclic\IncorrectDependenciesClass\''
|
||||
);
|
||||
$this->di->instantiate('FailDependenciesCyclic\IncorrectDependenciesClass');
|
||||
}
|
||||
|
||||
public function testFailDependenciesInChain()
|
||||
{
|
||||
require_once codecept_data_dir().'FailDependenciesInChain.php';
|
||||
$this->injectionShouldFail('Failed to resolve dependency \'FailDependenciesInChain\AnotherClass\'');
|
||||
$this->di->instantiate('FailDependenciesInChain\IncorrectDependenciesClass');
|
||||
}
|
||||
|
||||
public function testFailDependenciesNonExistent()
|
||||
{
|
||||
require_once codecept_data_dir().'FailDependenciesNonExistent.php';
|
||||
$this->injectionShouldFail('Class FailDependenciesNonExistent\NonExistentClass does not exist');
|
||||
$this->di->instantiate('FailDependenciesNonExistent\IncorrectDependenciesClass');
|
||||
}
|
||||
|
||||
public function testFailDependenciesPrimitiveParam()
|
||||
{
|
||||
require_once codecept_data_dir().'FailDependenciesPrimitiveParam.php';
|
||||
$this->injectionShouldFail('Parameter \'required\' must have default value');
|
||||
$this->di->instantiate('FailDependenciesPrimitiveParam\IncorrectDependenciesClass');
|
||||
}
|
||||
}
|
||||
34
vendor/codeception/base/tests/unit/Codeception/Lib/Driver/DbTest.php
vendored
Normal file
34
vendor/codeception/base/tests/unit/Codeception/Lib/Driver/DbTest.php
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
use \Codeception\Lib\Driver\Db;
|
||||
use \Codeception\Test\Unit;
|
||||
use \Codeception\Util\ReflectionHelper;
|
||||
|
||||
/**
|
||||
* @group appveyor
|
||||
* @group db
|
||||
*/
|
||||
class DbTest extends Unit
|
||||
{
|
||||
/**
|
||||
* @dataProvider getWhereCriteria
|
||||
*/
|
||||
public function testGenerateWhereClause($criteria, $expectedResult)
|
||||
{
|
||||
$db = new Db('sqlite:tests/data/sqlite.db','root','');
|
||||
$result = ReflectionHelper::invokePrivateMethod($db, 'generateWhereClause', [&$criteria]);
|
||||
$this->assertEquals($expectedResult, $result);
|
||||
}
|
||||
|
||||
public function getWhereCriteria()
|
||||
{
|
||||
return [
|
||||
'like' => [['email like' => 'mail.ua'], 'WHERE "email" LIKE ? '],
|
||||
'<=' => [['id <=' => '5'], 'WHERE "id" <= ? '],
|
||||
'<' => [['id <' => '5'], 'WHERE "id" < ? '],
|
||||
'>=' => [['id >=' => '5'], 'WHERE "id" >= ? '],
|
||||
'>' => [['id >' => '5'], 'WHERE "id" > ? '],
|
||||
'!=' => [['id !=' => '5'], 'WHERE "id" != ? '],
|
||||
];
|
||||
}
|
||||
}
|
||||
151
vendor/codeception/base/tests/unit/Codeception/Lib/Driver/MysqlTest.php
vendored
Normal file
151
vendor/codeception/base/tests/unit/Codeception/Lib/Driver/MysqlTest.php
vendored
Normal file
@@ -0,0 +1,151 @@
|
||||
<?php
|
||||
|
||||
use \Codeception\Lib\Driver\Db;
|
||||
use \Codeception\Test\Unit;
|
||||
|
||||
/**
|
||||
* @group appveyor
|
||||
* @group db
|
||||
*/
|
||||
class MysqlTest extends Unit
|
||||
{
|
||||
protected static $config = [
|
||||
'dsn' => 'mysql:host=localhost;dbname=codeception_test',
|
||||
'user' => 'root',
|
||||
'password' => ''
|
||||
];
|
||||
|
||||
protected static $sql;
|
||||
/**
|
||||
* @var \Codeception\Lib\Driver\MySql
|
||||
*/
|
||||
protected $mysql;
|
||||
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
if (getenv('APPVEYOR')) {
|
||||
self::$config['password'] = 'Password12!';
|
||||
}
|
||||
$sql = file_get_contents(\Codeception\Configuration::dataDir() . '/dumps/mysql.sql');
|
||||
$sql = preg_replace('%/\*(?:(?!\*/).)*\*/%s', "", $sql);
|
||||
self::$sql = explode("\n", $sql);
|
||||
try {
|
||||
$mysql = Db::create(self::$config['dsn'], self::$config['user'], self::$config['password']);
|
||||
$mysql->cleanup();
|
||||
} catch (\Exception $e) {
|
||||
}
|
||||
}
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
try {
|
||||
$this->mysql = Db::create(self::$config['dsn'], self::$config['user'], self::$config['password']);
|
||||
} catch (\Exception $e) {
|
||||
$this->markTestSkipped('Couldn\'t establish connection to database: ' . $e->getMessage());
|
||||
}
|
||||
$this->mysql->cleanup();
|
||||
$this->mysql->load(self::$sql);
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
if (isset($this->mysql)) {
|
||||
$this->mysql->cleanup();
|
||||
}
|
||||
}
|
||||
|
||||
public function testCleanupDatabase()
|
||||
{
|
||||
$this->assertNotEmpty($this->mysql->getDbh()->query("SHOW TABLES")->fetchAll());
|
||||
$this->mysql->cleanup();
|
||||
$this->assertEmpty($this->mysql->getDbh()->query("SHOW TABLES")->fetchAll());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group appveyor
|
||||
*/
|
||||
public function testLoadDump()
|
||||
{
|
||||
$res = $this->mysql->getDbh()->query("select * from users where name = 'davert'");
|
||||
$this->assertNotEquals(false, $res);
|
||||
$this->assertGreaterThan(0, $res->rowCount());
|
||||
|
||||
$res = $this->mysql->getDbh()->query("select * from groups where name = 'coders'");
|
||||
$this->assertNotEquals(false, $res);
|
||||
$this->assertGreaterThan(0, $res->rowCount());
|
||||
}
|
||||
|
||||
public function testGetSingleColumnPrimaryKey()
|
||||
{
|
||||
$this->assertEquals(['id'], $this->mysql->getPrimaryKey('order'));
|
||||
}
|
||||
|
||||
public function testGetCompositePrimaryKey()
|
||||
{
|
||||
$this->assertEquals(['group_id', 'id'], $this->mysql->getPrimaryKey('composite_pk'));
|
||||
}
|
||||
|
||||
public function testGetEmptyArrayIfTableHasNoPrimaryKey()
|
||||
{
|
||||
$this->assertEquals([], $this->mysql->getPrimaryKey('no_pk'));
|
||||
}
|
||||
|
||||
public function testGetPrimaryColumnOfTableUsingReservedWordAsTableName()
|
||||
{
|
||||
$this->assertEquals('id', $this->mysql->getPrimaryColumn('order'));
|
||||
}
|
||||
|
||||
public function testGetPrimaryColumnThrowsExceptionIfTableHasCompositePrimaryKey()
|
||||
{
|
||||
$this->setExpectedException(
|
||||
'\Exception',
|
||||
'getPrimaryColumn method does not support composite primary keys, use getPrimaryKey instead'
|
||||
);
|
||||
$this->mysql->getPrimaryColumn('composite_pk');
|
||||
}
|
||||
|
||||
public function testDeleteFromTableUsingReservedWordAsTableName()
|
||||
{
|
||||
$this->mysql->deleteQuery('order', 1);
|
||||
$res = $this->mysql->getDbh()->query("select id from `order` where id = 1");
|
||||
$this->assertEquals(0, $res->rowCount());
|
||||
}
|
||||
|
||||
public function testDeleteFromTableUsingReservedWordAsPrimaryKey()
|
||||
{
|
||||
$this->mysql->deleteQuery('table_with_reserved_primary_key', 1, 'unique');
|
||||
$res = $this->mysql->getDbh()->query("select name from `table_with_reserved_primary_key` where `unique` = 1");
|
||||
$this->assertEquals(0, $res->rowCount());
|
||||
}
|
||||
|
||||
public function testSelectWithBooleanParam()
|
||||
{
|
||||
$res = $this->mysql->executeQuery("select `id` from `users` where `is_active` = ?", [false]);
|
||||
$this->assertEquals(1, $res->rowCount());
|
||||
}
|
||||
|
||||
public function testInsertIntoBitField()
|
||||
{
|
||||
if (getenv('WERCKER_ROOT')) {
|
||||
$this->markTestSkipped('Disabled on Wercker CI');
|
||||
}
|
||||
$res = $this->mysql->executeQuery(
|
||||
"insert into `users`(`id`,`name`,`email`,`is_active`,`created_at`) values (?,?,?,?,?)",
|
||||
[5,'insert.test','insert.test@mail.ua',false,'2012-02-01 21:17:47']
|
||||
);
|
||||
$this->assertEquals(1, $res->rowCount());
|
||||
}
|
||||
|
||||
/**
|
||||
* THis will fail if MariaDb is used
|
||||
*/
|
||||
public function testLoadThrowsExceptionWhenDumpFileContainsSyntaxError()
|
||||
{
|
||||
$sql = "INSERT INTO `users` (`name`) VALS('')";
|
||||
$expectedMessage = 'You have an error in your SQL syntax; ' .
|
||||
'check the manual that corresponds to your MySQL server version for the right syntax to use near ' .
|
||||
"'VALS('')' at line 1\nSQL query being executed: \n" . $sql;
|
||||
$this->setExpectedException('Codeception\Exception\ModuleException', $expectedMessage);
|
||||
$this->mysql->load([$sql]);
|
||||
}
|
||||
}
|
||||
160
vendor/codeception/base/tests/unit/Codeception/Lib/Driver/PostgresTest.php
vendored
Normal file
160
vendor/codeception/base/tests/unit/Codeception/Lib/Driver/PostgresTest.php
vendored
Normal file
@@ -0,0 +1,160 @@
|
||||
<?php
|
||||
|
||||
use \Codeception\Lib\Driver\Db;
|
||||
use \Codeception\Test\Unit;
|
||||
|
||||
/**
|
||||
* @group appveyor
|
||||
* @group db
|
||||
*/
|
||||
class PostgresTest extends Unit
|
||||
{
|
||||
protected static $config = [
|
||||
'dsn' => 'pgsql:host=localhost;dbname=codeception_test',
|
||||
'user' => 'postgres',
|
||||
'password' => null,
|
||||
];
|
||||
|
||||
protected static $sql;
|
||||
protected $postgres;
|
||||
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
if (!function_exists('pg_connect')) {
|
||||
return;
|
||||
}
|
||||
if (getenv('APPVEYOR')) {
|
||||
self::$config['password'] = 'Password12!';
|
||||
}
|
||||
$dumpFile = 'dumps/postgres.sql';
|
||||
if (defined('HHVM_VERSION')) {
|
||||
$dumpFile = 'dumps/postgres-hhvm.sql';
|
||||
}
|
||||
$sql = file_get_contents(codecept_data_dir($dumpFile));
|
||||
$sql = preg_replace('%/\*(?:(?!\*/).)*\*/%s', '', $sql);
|
||||
self::$sql = explode("\n", $sql);
|
||||
}
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
try {
|
||||
$this->postgres = Db::create(self::$config['dsn'], self::$config['user'], self::$config['password']);
|
||||
$this->postgres->cleanup();
|
||||
} catch (\Exception $e) {
|
||||
$this->markTestSkipped('Coudn\'t establish connection to database: ' . $e->getMessage());
|
||||
}
|
||||
$this->postgres->load(self::$sql);
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
if (isset($this->postgres)) {
|
||||
$this->postgres->cleanup();
|
||||
}
|
||||
}
|
||||
|
||||
public function testCleanupDatabase()
|
||||
{
|
||||
$this->assertNotEmpty(
|
||||
$this->postgres->getDbh()->query("SELECT * FROM pg_tables where schemaname = 'public'")->fetchAll()
|
||||
);
|
||||
$this->postgres->cleanup();
|
||||
$this->assertEmpty(
|
||||
$this->postgres->getDbh()->query("SELECT * FROM pg_tables where schemaname = 'public'")->fetchAll()
|
||||
);
|
||||
}
|
||||
|
||||
public function testCleanupDatabaseDeletesTypes()
|
||||
{
|
||||
$customTypes = ['composite_type', 'enum_type', 'range_type', 'base_type'];
|
||||
foreach ($customTypes as $customType) {
|
||||
$this->assertNotEmpty(
|
||||
$this->postgres->getDbh()
|
||||
->query("SELECT 1 FROM pg_type WHERE typname = '" . $customType . "';")
|
||||
->fetchAll()
|
||||
);
|
||||
}
|
||||
$this->postgres->cleanup();
|
||||
foreach ($customTypes as $customType) {
|
||||
$this->assertEmpty(
|
||||
$this->postgres->getDbh()
|
||||
->query("SELECT 1 FROM pg_type WHERE typname = '" . $customType . "';")
|
||||
->fetchAll()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function testLoadDump()
|
||||
{
|
||||
$res = $this->postgres->getDbh()->query("select * from users where name = 'davert'");
|
||||
$this->assertNotEquals(false, $res);
|
||||
$this->assertGreaterThan(0, $res->rowCount());
|
||||
|
||||
$res = $this->postgres->getDbh()->query("select * from groups where name = 'coders'");
|
||||
$this->assertNotEquals(false, $res);
|
||||
$this->assertGreaterThan(0, $res->rowCount());
|
||||
|
||||
$res = $this->postgres->getDbh()->query("select * from users where email = 'user2@example.org'");
|
||||
$this->assertNotEquals(false, $res);
|
||||
$this->assertGreaterThan(0, $res->rowCount());
|
||||
|
||||
$res = $this->postgres->getDbh()
|
||||
->query("select * from anotherschema.users where email = 'schemauser@example.org'");
|
||||
$this->assertEquals(1, $res->rowCount());
|
||||
}
|
||||
|
||||
public function testSelectWithEmptyCriteria()
|
||||
{
|
||||
$emptyCriteria = [];
|
||||
$generatedSql = $this->postgres->select('test_column', 'test_table', $emptyCriteria);
|
||||
|
||||
$this->assertNotContains('where', $generatedSql);
|
||||
}
|
||||
|
||||
public function testGetSingleColumnPrimaryKey()
|
||||
{
|
||||
$this->assertEquals(['id'], $this->postgres->getPrimaryKey('order'));
|
||||
}
|
||||
|
||||
public function testGetCompositePrimaryKey()
|
||||
{
|
||||
$this->assertEquals(['group_id', 'id'], $this->postgres->getPrimaryKey('composite_pk'));
|
||||
}
|
||||
|
||||
public function testGetEmptyArrayIfTableHasNoPrimaryKey()
|
||||
{
|
||||
$this->assertEquals([], $this->postgres->getPrimaryKey('no_pk'));
|
||||
}
|
||||
|
||||
public function testLastInsertIdReturnsSequenceValueWhenNonStandardSequenceNameIsUsed()
|
||||
{
|
||||
$this->postgres->executeQuery('INSERT INTO seqnames(name) VALUES(?)',['test']);
|
||||
$this->assertEquals(1, $this->postgres->lastInsertId('seqnames'));
|
||||
}
|
||||
|
||||
public function testGetPrimaryColumnOfTableUsingReservedWordAsTableName()
|
||||
{
|
||||
$this->assertEquals('id', $this->postgres->getPrimaryColumn('order'));
|
||||
}
|
||||
|
||||
public function testGetPrimaryColumnThrowsExceptionIfTableHasCompositePrimaryKey()
|
||||
{
|
||||
$this->setExpectedException(
|
||||
'\Exception',
|
||||
'getPrimaryColumn method does not support composite primary keys, use getPrimaryKey instead'
|
||||
);
|
||||
$this->postgres->getPrimaryColumn('composite_pk');
|
||||
}
|
||||
|
||||
/**
|
||||
* @issue https://github.com/Codeception/Codeception/issues/4059
|
||||
*/
|
||||
public function testLoadDumpEndingWithoutDelimiter()
|
||||
{
|
||||
$newDriver = new \Codeception\Lib\Driver\PostgreSql(self::$config['dsn'], self::$config['user'], self::$config['password']);
|
||||
$newDriver->load(['INSERT INTO empty_table VALUES(1, \'test\')']);
|
||||
$res = $newDriver->getDbh()->query("select * from empty_table where field = 'test'");
|
||||
$this->assertNotEquals(false, $res);
|
||||
$this->assertNotEmpty($res->fetchAll());
|
||||
}
|
||||
}
|
||||
129
vendor/codeception/base/tests/unit/Codeception/Lib/Driver/SqliteTest.php
vendored
Normal file
129
vendor/codeception/base/tests/unit/Codeception/Lib/Driver/SqliteTest.php
vendored
Normal file
@@ -0,0 +1,129 @@
|
||||
<?php
|
||||
|
||||
use \Codeception\Lib\Driver\Db;
|
||||
use \Codeception\Test\Unit;
|
||||
|
||||
/**
|
||||
* @group db
|
||||
* Class SqliteTest
|
||||
*/
|
||||
class SqliteTest extends Unit
|
||||
{
|
||||
protected static $config = array(
|
||||
'dsn' => 'sqlite:tests/data/sqlite.db',
|
||||
'user' => 'root',
|
||||
'password' => ''
|
||||
);
|
||||
|
||||
/**
|
||||
* @var \Codeception\Lib\Driver\Sqlite
|
||||
*/
|
||||
protected static $sqlite;
|
||||
protected static $sql;
|
||||
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
if (version_compare(PHP_VERSION, '5.5.0', '<')) {
|
||||
$dumpFile = '/dumps/sqlite-54.sql';
|
||||
} else {
|
||||
$dumpFile = '/dumps/sqlite.sql';
|
||||
}
|
||||
|
||||
$sql = file_get_contents(\Codeception\Configuration::dataDir() . $dumpFile);
|
||||
$sql = preg_replace('%/\*(?:(?!\*/).)*\*/%s', "", $sql);
|
||||
self::$sql = explode("\n", $sql);
|
||||
}
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
self::$sqlite = Db::create(self::$config['dsn'], self::$config['user'], self::$config['password']);
|
||||
self::$sqlite->cleanup();
|
||||
self::$sqlite->load(self::$sql);
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
if (isset(self::$sqlite)) {
|
||||
self::$sqlite->cleanup();
|
||||
}
|
||||
}
|
||||
|
||||
public function testLoadDump()
|
||||
{
|
||||
$res = self::$sqlite->getDbh()->query("select * from users where name = 'davert'");
|
||||
$this->assertNotEquals(false, $res);
|
||||
$this->assertNotEmpty($res->fetchAll());
|
||||
|
||||
$res = self::$sqlite->getDbh()->query("select * from groups where name = 'coders'");
|
||||
$this->assertNotEquals(false, $res);
|
||||
$this->assertNotEmpty($res->fetchAll());
|
||||
}
|
||||
|
||||
public function testGetPrimaryKeyReturnsRowIdIfTableHasIt()
|
||||
{
|
||||
$this->assertEquals(['_ROWID_'], self::$sqlite->getPrimaryKey('groups'));
|
||||
}
|
||||
|
||||
public function testGetPrimaryKeyReturnsRowIdIfTableHasNoPrimaryKey()
|
||||
{
|
||||
$this->assertEquals(['_ROWID_'], self::$sqlite->getPrimaryKey('no_pk'));
|
||||
}
|
||||
|
||||
public function testGetSingleColumnPrimaryKeyWhenTableHasNoRowId()
|
||||
{
|
||||
if (version_compare(PHP_VERSION, '5.5.0', '<')) {
|
||||
$this->markTestSkipped('Sqlite does not support WITHOUT ROWID on travis');
|
||||
}
|
||||
$this->assertEquals(['id'], self::$sqlite->getPrimaryKey('order'));
|
||||
}
|
||||
|
||||
public function testGetCompositePrimaryKeyWhenTableHasNoRowId()
|
||||
{
|
||||
if (version_compare(PHP_VERSION, '5.5.0', '<')) {
|
||||
$this->markTestSkipped('Sqlite does not support WITHOUT ROWID on travis');
|
||||
}
|
||||
$this->assertEquals(['group_id', 'id'], self::$sqlite->getPrimaryKey('composite_pk'));
|
||||
}
|
||||
|
||||
public function testGetPrimaryColumnOfTableUsingReservedWordAsTableNameWhenTableHasNoRowId()
|
||||
{
|
||||
if (version_compare(PHP_VERSION, '5.5.0', '<')) {
|
||||
$this->markTestSkipped('Sqlite does not support WITHOUT ROWID on travis');
|
||||
}
|
||||
$this->assertEquals('id', self::$sqlite->getPrimaryColumn('order'));
|
||||
}
|
||||
|
||||
public function testGetPrimaryColumnThrowsExceptionIfTableHasCompositePrimaryKey()
|
||||
{
|
||||
if (version_compare(PHP_VERSION, '5.5.0', '<')) {
|
||||
$this->markTestSkipped('Sqlite does not support WITHOUT ROWID on travis');
|
||||
}
|
||||
$this->setExpectedException(
|
||||
'\Exception',
|
||||
'getPrimaryColumn method does not support composite primary keys, use getPrimaryKey instead'
|
||||
);
|
||||
self::$sqlite->getPrimaryColumn('composite_pk');
|
||||
}
|
||||
|
||||
public function testThrowsExceptionIfInMemoryDatabaseIsUsed()
|
||||
{
|
||||
$this->setExpectedException(
|
||||
'\Codeception\Exception\ModuleException',
|
||||
':memory: database is not supported'
|
||||
);
|
||||
|
||||
Db::create('sqlite::memory:', '', '');
|
||||
}
|
||||
|
||||
/**
|
||||
* @issue https://github.com/Codeception/Codeception/issues/4059
|
||||
*/
|
||||
public function testLoadDumpEndingWithoutDelimiter()
|
||||
{
|
||||
$newDriver = new \Codeception\Lib\Driver\Sqlite(self::$config['dsn'], '', '');
|
||||
$newDriver->load(['INSERT INTO empty_table VALUES(1, "test")']);
|
||||
$res = $newDriver->getDbh()->query("select * from empty_table where field = 'test'");
|
||||
$this->assertNotEquals(false, $res);
|
||||
$this->assertNotEmpty($res->fetchAll());
|
||||
}
|
||||
}
|
||||
93
vendor/codeception/base/tests/unit/Codeception/Lib/GroupManagerTest.php
vendored
Normal file
93
vendor/codeception/base/tests/unit/Codeception/Lib/GroupManagerTest.php
vendored
Normal file
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
namespace Codeception\Lib;
|
||||
|
||||
use Codeception\Util\Stub;
|
||||
|
||||
class GroupManagerTest extends \Codeception\Test\Unit
|
||||
{
|
||||
/**
|
||||
* @var \Codeception\Lib\GroupManager
|
||||
*/
|
||||
protected $manager;
|
||||
|
||||
// tests
|
||||
public function testGroupsFromArray()
|
||||
{
|
||||
$this->manager = new GroupManager(['important' => ['UserTest.php:testName', 'PostTest.php']]);
|
||||
$test1 = $this->makeTestCase('UserTest.php', 'testName');
|
||||
$test2 = $this->makeTestCase('PostTest.php');
|
||||
$test3 = $this->makeTestCase('UserTest.php', 'testNot');
|
||||
$this->assertContains('important', $this->manager->groupsForTest($test1));
|
||||
$this->assertContains('important', $this->manager->groupsForTest($test2));
|
||||
$this->assertNotContains('important', $this->manager->groupsForTest($test3));
|
||||
}
|
||||
|
||||
public function testGroupsFromFile()
|
||||
{
|
||||
$this->manager = new GroupManager(['important' => 'tests/data/test_groups']);
|
||||
$test1 = $this->makeTestCase('tests/UserTest.php', 'testName');
|
||||
$test2 = $this->makeTestCase('tests/PostTest.php');
|
||||
$test3 = $this->makeTestCase('tests/UserTest.php', 'testNot');
|
||||
$this->assertContains('important', $this->manager->groupsForTest($test1));
|
||||
$this->assertContains('important', $this->manager->groupsForTest($test2));
|
||||
$this->assertNotContains('important', $this->manager->groupsForTest($test3));
|
||||
}
|
||||
|
||||
public function testGroupsFromFileOnWindows()
|
||||
{
|
||||
$this->manager = new GroupManager(['important' => 'tests/data/group_3']);
|
||||
$test = $this->makeTestCase('tests/WinTest.php');
|
||||
$this->assertContains('important', $this->manager->groupsForTest($test));
|
||||
}
|
||||
|
||||
public function testGroupsFromArrayOnWindows()
|
||||
{
|
||||
$this->manager = new GroupManager(['important' => ['tests\WinTest.php']]);
|
||||
$test = $this->makeTestCase('tests/WinTest.php');
|
||||
$this->assertContains('important', $this->manager->groupsForTest($test));
|
||||
}
|
||||
|
||||
public function testGroupsByPattern()
|
||||
{
|
||||
$this->manager = new GroupManager(['group_*' => 'tests/data/group_*']);
|
||||
$test1 = $this->makeTestCase('tests/UserTest.php');
|
||||
$test2 = $this->makeTestCase('tests/PostTest.php');
|
||||
$this->assertContains('group_1', $this->manager->groupsForTest($test1));
|
||||
$this->assertContains('group_2', $this->manager->groupsForTest($test2));
|
||||
}
|
||||
|
||||
public function testGroupsByDifferentPattern()
|
||||
{
|
||||
$this->manager = new GroupManager(['g_*' => 'tests/data/group_*']);
|
||||
$test1 = $this->makeTestCase('tests/UserTest.php');
|
||||
$test2 = $this->makeTestCase('tests/PostTest.php');
|
||||
$this->assertContains('g_1', $this->manager->groupsForTest($test1));
|
||||
$this->assertContains('g_2', $this->manager->groupsForTest($test2));
|
||||
}
|
||||
|
||||
public function testGroupsFileHandlesWhitespace()
|
||||
{
|
||||
$this->manager = new GroupManager(['whitespace_group_test' => 'tests/data/whitespace_group_test']);
|
||||
$goodTest = $this->makeTestCase('tests/WhitespaceTest.php');
|
||||
$badTest = $this->makeTestCase('');
|
||||
|
||||
$this->assertContains('whitespace_group_test', $this->manager->groupsForTest($goodTest));
|
||||
$this->assertEmpty($this->manager->groupsForTest($badTest));
|
||||
}
|
||||
|
||||
protected function makeTestCase($file, $name = '')
|
||||
{
|
||||
return Stub::make(
|
||||
'\Codeception\Lib\DescriptiveTestCase',
|
||||
[
|
||||
'getReportFields' => ['file' => codecept_root_dir() . $file],
|
||||
'getName' => $name
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class DescriptiveTestCase extends \Codeception\Test\Unit
|
||||
{
|
||||
|
||||
}
|
||||
457
vendor/codeception/base/tests/unit/Codeception/Lib/ModuleContainerTest.php
vendored
Normal file
457
vendor/codeception/base/tests/unit/Codeception/Lib/ModuleContainerTest.php
vendored
Normal file
@@ -0,0 +1,457 @@
|
||||
<?php
|
||||
namespace Codeception\Lib;
|
||||
|
||||
use Codeception\Lib\Interfaces\ConflictsWithModule;
|
||||
use Codeception\Lib\Interfaces\DependsOnModule;
|
||||
use Codeception\Test\Unit;
|
||||
use Codeception\Util\Stub;
|
||||
|
||||
// @codingStandardsIgnoreFile
|
||||
class ModuleContainerTest extends Unit
|
||||
{
|
||||
use \Codeception\Specify;
|
||||
/**
|
||||
* @var ModuleContainer
|
||||
*/
|
||||
protected $moduleContainer;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->moduleContainer = new ModuleContainer(Stub::make('Codeception\Lib\Di'), []);
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
\Codeception\Module\UniversalFramework::$includeInheritedActions = true;
|
||||
\Codeception\Module\UniversalFramework::$onlyActions = [];
|
||||
\Codeception\Module\UniversalFramework::$excludeActions = [];
|
||||
\Codeception\Module\UniversalFramework::$aliases = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @group core
|
||||
* @throws \Codeception\Exception\ConfigurationException
|
||||
*/
|
||||
public function testCreateModule()
|
||||
{
|
||||
$module = $this->moduleContainer->create('EmulateModuleHelper');
|
||||
$this->assertInstanceOf('Codeception\Module\EmulateModuleHelper', $module);
|
||||
|
||||
$module = $this->moduleContainer->create('Codeception\Module\EmulateModuleHelper');
|
||||
$this->assertInstanceOf('Codeception\Module\EmulateModuleHelper', $module);
|
||||
|
||||
$this->assertTrue($this->moduleContainer->hasModule('EmulateModuleHelper'));
|
||||
$this->assertInstanceOf(
|
||||
'Codeception\Module\EmulateModuleHelper',
|
||||
$this->moduleContainer->getModule('EmulateModuleHelper')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group core
|
||||
*/
|
||||
public function testActions()
|
||||
{
|
||||
$this->moduleContainer->create('EmulateModuleHelper');
|
||||
$actions = $this->moduleContainer->getActions();
|
||||
$this->assertArrayHasKey('seeEquals', $actions);
|
||||
$this->assertEquals('EmulateModuleHelper', $actions['seeEquals']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group core
|
||||
*/
|
||||
public function testActionsInExtendedModule()
|
||||
{
|
||||
$this->moduleContainer->create('\Codeception\Module\UniversalFramework');
|
||||
$actions = $this->moduleContainer->getActions();
|
||||
$this->assertArrayHasKey('amOnPage', $actions);
|
||||
$this->assertArrayHasKey('see', $actions);
|
||||
$this->assertArrayHasKey('click', $actions);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group core
|
||||
*/
|
||||
public function testActionsInExtendedButNotInheritedModule()
|
||||
{
|
||||
\Codeception\Module\UniversalFramework::$includeInheritedActions = false;
|
||||
$this->moduleContainer->create('\Codeception\Module\UniversalFramework');
|
||||
$actions = $this->moduleContainer->getActions();
|
||||
$this->assertArrayNotHasKey('amOnPage', $actions);
|
||||
$this->assertArrayNotHasKey('see', $actions);
|
||||
$this->assertArrayNotHasKey('click', $actions);
|
||||
$this->assertArrayHasKey('useUniversalFramework', $actions);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group core
|
||||
*/
|
||||
public function testExplicitlySetActionsOnNotInherited()
|
||||
{
|
||||
\Codeception\Module\UniversalFramework::$includeInheritedActions = false;
|
||||
\Codeception\Module\UniversalFramework::$onlyActions = ['see'];
|
||||
$this->moduleContainer->create('\Codeception\Module\UniversalFramework');
|
||||
$actions = $this->moduleContainer->getActions();
|
||||
$this->assertArrayNotHasKey('amOnPage', $actions);
|
||||
$this->assertArrayHasKey('see', $actions);
|
||||
$this->assertArrayNotHasKey('click', $actions);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group core
|
||||
*/
|
||||
public function testActionsExplicitlySetForNotInheritedModule()
|
||||
{
|
||||
\Codeception\Module\UniversalFramework::$onlyActions = ['see'];
|
||||
$this->moduleContainer->create('\Codeception\Module\UniversalFramework');
|
||||
$actions = $this->moduleContainer->getActions();
|
||||
$this->assertArrayNotHasKey('amOnPage', $actions);
|
||||
$this->assertArrayHasKey('see', $actions);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group core
|
||||
*/
|
||||
public function testCreateModuleWithoutRequiredFields()
|
||||
{
|
||||
$this->setExpectedException('\Codeception\Exception\ModuleConfigException');
|
||||
$this->moduleContainer->create('Codeception\Lib\StubModule');
|
||||
}
|
||||
|
||||
/**
|
||||
* @group core
|
||||
*/
|
||||
public function testCreateModuleWithCorrectConfig()
|
||||
{
|
||||
$config = [
|
||||
'modules' => [
|
||||
'config' => [
|
||||
'Codeception\Lib\StubModule' => [
|
||||
'firstField' => 'firstValue',
|
||||
'secondField' => 'secondValue',
|
||||
]
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
$this->moduleContainer = new ModuleContainer(Stub::make('Codeception\Lib\Di'), $config);
|
||||
$module = $this->moduleContainer->create('Codeception\Lib\StubModule');
|
||||
|
||||
$this->assertEquals('firstValue', $module->_getFirstField());
|
||||
$this->assertEquals('secondValue', $module->_getSecondField());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group core
|
||||
*/
|
||||
public function testReconfigureModule()
|
||||
{
|
||||
$config = [
|
||||
'modules' => [
|
||||
'config' => [
|
||||
'Codeception\Lib\StubModule' => [
|
||||
'firstField' => 'firstValue',
|
||||
'secondField' => 'secondValue',
|
||||
]
|
||||
]
|
||||
]
|
||||
];
|
||||
$this->moduleContainer = new ModuleContainer(Stub::make('Codeception\Lib\Di'), $config);
|
||||
$module = $this->moduleContainer->create('Codeception\Lib\StubModule');
|
||||
$module->_reconfigure(['firstField' => '1st', 'secondField' => '2nd']);
|
||||
$this->assertEquals('1st', $module->_getFirstField());
|
||||
$this->assertEquals('2nd', $module->_getSecondField());
|
||||
$module->_resetConfig();
|
||||
$this->assertEquals('firstValue', $module->_getFirstField());
|
||||
$this->assertEquals('secondValue', $module->_getSecondField());
|
||||
}
|
||||
|
||||
public function testConflictsByModuleName()
|
||||
{
|
||||
$this->setExpectedException('Codeception\Exception\ModuleConflictException');
|
||||
$this->moduleContainer->create('Codeception\Lib\ConflictedModule');
|
||||
$this->moduleContainer->create('Cli');
|
||||
$this->moduleContainer->validateConflicts();
|
||||
}
|
||||
|
||||
|
||||
public function testConflictsByClass()
|
||||
{
|
||||
$this->setExpectedException('Codeception\Exception\ModuleConflictException');
|
||||
$this->moduleContainer->create('Codeception\Lib\ConflictedModule2');
|
||||
$this->moduleContainer->create('Cli');
|
||||
$this->moduleContainer->validateConflicts();
|
||||
}
|
||||
|
||||
public function testConflictsByInterface()
|
||||
{
|
||||
$this->setExpectedException('Codeception\Exception\ModuleConflictException');
|
||||
$this->moduleContainer->create('Codeception\Lib\ConflictedModule3');
|
||||
$this->moduleContainer->create('Symfony2');
|
||||
$this->moduleContainer->validateConflicts();
|
||||
}
|
||||
|
||||
public function testConflictsByWebInterface()
|
||||
{
|
||||
$this->setExpectedException('Codeception\Exception\ModuleConflictException');
|
||||
$this->moduleContainer->create('Laravel5');
|
||||
$this->moduleContainer->create('Symfony2');
|
||||
$this->moduleContainer->validateConflicts();
|
||||
}
|
||||
|
||||
public function testConflictsForREST()
|
||||
{
|
||||
$config = ['modules' =>
|
||||
['config' => [
|
||||
'REST' => [
|
||||
'depends' => 'ZF1',
|
||||
]
|
||||
]
|
||||
]
|
||||
];
|
||||
$this->moduleContainer = new ModuleContainer(Stub::make('Codeception\Lib\Di'), $config);
|
||||
$this->moduleContainer->create('ZF1');
|
||||
$this->moduleContainer->create('REST');
|
||||
$this->moduleContainer->validateConflicts();
|
||||
}
|
||||
|
||||
public function testConflictsOnDependentModules()
|
||||
{
|
||||
$config = ['modules' =>
|
||||
['config' => [
|
||||
'WebDriver' => ['url' => 'localhost', 'browser' => 'firefox'],
|
||||
'REST' => [
|
||||
'depends' => 'PhpBrowser',
|
||||
]
|
||||
]
|
||||
]
|
||||
];
|
||||
$this->moduleContainer = new ModuleContainer(Stub::make('Codeception\Lib\Di'), $config);
|
||||
$this->moduleContainer->create('WebDriver');
|
||||
$this->moduleContainer->create('REST');
|
||||
$this->moduleContainer->validateConflicts();
|
||||
}
|
||||
|
||||
|
||||
public function testNoConflictsForPartedModules()
|
||||
{
|
||||
$config = ['modules' =>
|
||||
['config' => [
|
||||
'Laravel5' => [
|
||||
'part' => 'ORM',
|
||||
]
|
||||
]
|
||||
]
|
||||
];
|
||||
$this->moduleContainer = new ModuleContainer(Stub::make('Codeception\Lib\Di'), $config);
|
||||
$this->moduleContainer->create('Laravel5');
|
||||
$this->moduleContainer->create('Symfony2');
|
||||
$this->moduleContainer->validateConflicts();
|
||||
}
|
||||
|
||||
public function testModuleDependenciesFail()
|
||||
{
|
||||
$this->setExpectedException('Codeception\Exception\ModuleRequireException');
|
||||
$this->moduleContainer->create('Codeception\Lib\DependencyModule');
|
||||
}
|
||||
|
||||
public function testModuleDependencies()
|
||||
{
|
||||
$config = ['modules' => [
|
||||
'enabled' => ['Codeception\Lib\DependencyModule'],
|
||||
'config' => [
|
||||
'Codeception\Lib\DependencyModule' => [
|
||||
'depends' => 'Codeception\Lib\ConflictedModule'
|
||||
]
|
||||
]
|
||||
]];
|
||||
$this->moduleContainer = new ModuleContainer(Stub::make('Codeception\Lib\Di'), $config);
|
||||
$this->moduleContainer->create('Codeception\Lib\DependencyModule');
|
||||
$this->moduleContainer->hasModule('\Codeception\Lib\DependencyModule');
|
||||
}
|
||||
|
||||
public function testModuleParts1()
|
||||
{
|
||||
$config = ['modules' => [
|
||||
'enabled' => ['\Codeception\Lib\PartedModule'],
|
||||
'config' => [
|
||||
'\Codeception\Lib\PartedModule' => [
|
||||
'part' => 'one'
|
||||
]
|
||||
]
|
||||
]
|
||||
];
|
||||
$this->moduleContainer = new ModuleContainer(Stub::make('Codeception\Lib\Di'), $config);
|
||||
$this->moduleContainer->create('\Codeception\Lib\PartedModule');
|
||||
$actions = $this->moduleContainer->getActions();
|
||||
$this->assertArrayHasKey('partOne', $actions);
|
||||
$this->assertArrayNotHasKey('partTwo', $actions);
|
||||
}
|
||||
|
||||
public function testModuleParts2()
|
||||
{
|
||||
$config = ['modules' => [
|
||||
'enabled' => ['\Codeception\Lib\PartedModule'],
|
||||
'config' => ['\Codeception\Lib\PartedModule' => [
|
||||
'part' => ['Two']
|
||||
]
|
||||
]
|
||||
]
|
||||
];
|
||||
$this->moduleContainer = new ModuleContainer(Stub::make('Codeception\Lib\Di'), $config);
|
||||
$this->moduleContainer->create('\Codeception\Lib\PartedModule');
|
||||
$actions = $this->moduleContainer->getActions();
|
||||
$this->assertArrayHasKey('partTwo', $actions);
|
||||
$this->assertArrayNotHasKey('partOne', $actions);
|
||||
}
|
||||
|
||||
public function testShortConfigParts()
|
||||
{
|
||||
$config = [
|
||||
'modules' => [
|
||||
'enabled' => [
|
||||
['\Codeception\Lib\PartedModule' => [
|
||||
'part' => 'one'
|
||||
]
|
||||
]
|
||||
],
|
||||
]
|
||||
];
|
||||
$this->moduleContainer = new ModuleContainer(Stub::make('Codeception\Lib\Di'), $config);
|
||||
$this->moduleContainer->create('\Codeception\Lib\PartedModule');
|
||||
$actions = $this->moduleContainer->getActions();
|
||||
$this->assertArrayHasKey('partOne', $actions);
|
||||
$this->assertArrayNotHasKey('partTwo', $actions);
|
||||
}
|
||||
|
||||
public function testShortConfigFormat()
|
||||
{
|
||||
$config = [
|
||||
'modules' =>
|
||||
['enabled' => [
|
||||
['Codeception\Lib\StubModule' => [
|
||||
'firstField' => 'firstValue',
|
||||
'secondField' => 'secondValue',
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
$this->moduleContainer = new ModuleContainer(Stub::make('Codeception\Lib\Di'), $config);
|
||||
$module = $this->moduleContainer->create('Codeception\Lib\StubModule');
|
||||
|
||||
$this->assertEquals('firstValue', $module->_getFirstField());
|
||||
$this->assertEquals('secondValue', $module->_getSecondField());
|
||||
}
|
||||
|
||||
public function testShortConfigDependencies()
|
||||
{
|
||||
$config = ['modules' => [
|
||||
'enabled' => [['Codeception\Lib\DependencyModule' => [
|
||||
'depends' => 'Codeception\Lib\ConflictedModule'
|
||||
]]],
|
||||
]];
|
||||
$this->moduleContainer = new ModuleContainer(Stub::make('Codeception\Lib\Di'), $config);
|
||||
$this->moduleContainer->create('Codeception\Lib\DependencyModule');
|
||||
$this->moduleContainer->hasModule('\Codeception\Lib\DependencyModule');
|
||||
}
|
||||
|
||||
public function testInjectModuleIntoHelper()
|
||||
{
|
||||
$config = ['modules' => [
|
||||
'enabled' => ['Codeception\Lib\HelperModule'],
|
||||
]];
|
||||
$this->moduleContainer = new ModuleContainer(Stub::make('Codeception\Lib\Di'), $config);
|
||||
$this->moduleContainer->create('Codeception\Lib\HelperModule');
|
||||
$this->moduleContainer->hasModule('Codeception\Lib\HelperModule');
|
||||
}
|
||||
}
|
||||
|
||||
class StubModule extends \Codeception\Module
|
||||
{
|
||||
protected $requiredFields = [
|
||||
'firstField',
|
||||
'secondField',
|
||||
];
|
||||
|
||||
public function _getFirstField()
|
||||
{
|
||||
return $this->config['firstField'];
|
||||
}
|
||||
|
||||
public function _getSecondField()
|
||||
{
|
||||
return $this->config['secondField'];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
class HelperModule extends \Codeception\Module
|
||||
{
|
||||
public function _inject(ConflictedModule $module)
|
||||
{
|
||||
$this->module = $module;
|
||||
}
|
||||
}
|
||||
|
||||
class ConflictedModule extends \Codeception\Module implements ConflictsWithModule
|
||||
{
|
||||
public function _conflicts()
|
||||
{
|
||||
return 'Cli';
|
||||
}
|
||||
}
|
||||
|
||||
class ConflictedModule2 extends \Codeception\Module implements ConflictsWithModule
|
||||
{
|
||||
public function _conflicts()
|
||||
{
|
||||
return '\Codeception\Module\Cli';
|
||||
}
|
||||
}
|
||||
|
||||
class ConflictedModule3 extends \Codeception\Module implements ConflictsWithModule
|
||||
{
|
||||
public function _conflicts()
|
||||
{
|
||||
return 'Codeception\Lib\Interfaces\Web';
|
||||
}
|
||||
}
|
||||
|
||||
class DependencyModule extends \Codeception\Module implements DependsOnModule
|
||||
{
|
||||
public function _depends()
|
||||
{
|
||||
return ['Codeception\Lib\ConflictedModule' => 'Error message'];
|
||||
}
|
||||
|
||||
public function _inject()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
class PartedModule extends \Codeception\Module implements \Codeception\Lib\Interfaces\PartedModule
|
||||
{
|
||||
public function _parts()
|
||||
{
|
||||
return ['one'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @part one
|
||||
*/
|
||||
public function partOne()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @part two
|
||||
*/
|
||||
public function partTwo()
|
||||
{
|
||||
}
|
||||
}
|
||||
178
vendor/codeception/base/tests/unit/Codeception/Lib/ParserTest.php
vendored
Normal file
178
vendor/codeception/base/tests/unit/Codeception/Lib/ParserTest.php
vendored
Normal file
@@ -0,0 +1,178 @@
|
||||
<?php
|
||||
use Codeception\Lib\Parser;
|
||||
|
||||
/**
|
||||
* @group core
|
||||
* Class ParserTest
|
||||
*/
|
||||
class ParserTest extends \Codeception\Test\Unit
|
||||
{
|
||||
/**
|
||||
* @var Parser
|
||||
*/
|
||||
protected $parser;
|
||||
|
||||
/**
|
||||
* @var \Codeception\Scenario
|
||||
*/
|
||||
protected $scenario;
|
||||
|
||||
protected $testMetadata;
|
||||
|
||||
protected function _before()
|
||||
{
|
||||
$cept = new \Codeception\Test\Cept('demo', 'DemoCept.php');
|
||||
|
||||
$this->testMetadata = $cept->getMetadata();
|
||||
$this->scenario = new Codeception\Scenario($cept);
|
||||
$this->parser = new Parser($this->scenario, $this->testMetadata);
|
||||
}
|
||||
|
||||
public function testParsingFeature()
|
||||
{
|
||||
$code = "<?php\n \\\$I->wantTo('run this test'); ";
|
||||
$this->parser->parseFeature($code);
|
||||
$this->assertEquals('run this test', $this->scenario->getFeature());
|
||||
|
||||
$code = "<?php\n \\\$I->wantToTest('this run'); ";
|
||||
$this->parser->parseFeature($code);
|
||||
$this->assertEquals('test this run', $this->scenario->getFeature());
|
||||
}
|
||||
|
||||
public function testParsingWithWhitespace()
|
||||
{
|
||||
$code = "<?php\n \\\$I->wantTo( 'run this test' ); ";
|
||||
$this->parser->parseFeature($code);
|
||||
$this->assertEquals('run this test', $this->scenario->getFeature());
|
||||
}
|
||||
|
||||
public function testScenarioOptions()
|
||||
{
|
||||
$code = <<<EOF
|
||||
<?php
|
||||
// @group davert
|
||||
// @env windows
|
||||
|
||||
\$I = new AcceptanceTeser(\$scenario);
|
||||
EOF;
|
||||
|
||||
$this->parser->parseScenarioOptions($code);
|
||||
$this->assertContains('davert', $this->testMetadata->getGroups());
|
||||
$this->assertContains('windows', $this->testMetadata->getEnv());
|
||||
}
|
||||
|
||||
public function testCommentedInBlockScenarioOptions()
|
||||
{
|
||||
$code = <<<EOF
|
||||
<?php
|
||||
/**
|
||||
* @skip
|
||||
*/
|
||||
EOF;
|
||||
$this->parser->parseScenarioOptions($code);
|
||||
$this->assertTrue($this->testMetadata->isBlocked());
|
||||
}
|
||||
|
||||
public function testFeatureCommented()
|
||||
{
|
||||
$code = "<?php\n //\\\$I->wantTo('run this test'); ";
|
||||
$this->parser->parseFeature($code);
|
||||
$this->assertNull($this->scenario->getFeature());
|
||||
|
||||
$code = "<?php\n /*\n \\\$I->wantTo('run this test'); \n */";
|
||||
$this->parser->parseFeature($code);
|
||||
$this->assertNull($this->scenario->getFeature());
|
||||
}
|
||||
|
||||
public function testScenarioSkipOptionsHandled()
|
||||
{
|
||||
$code = "<?php\n // @skip pass along";
|
||||
$this->parser->parseScenarioOptions($code);
|
||||
$this->assertTrue($this->testMetadata->isBlocked());
|
||||
}
|
||||
|
||||
public function testScenarioIncompleteOptionHandled()
|
||||
{
|
||||
$code = "<?php\n // @incomplete not ready yet";
|
||||
$this->parser->parseScenarioOptions($code);
|
||||
$this->assertTrue($this->testMetadata->isBlocked());
|
||||
}
|
||||
|
||||
public function testSteps()
|
||||
{
|
||||
$code = file_get_contents(\Codeception\Configuration::projectDir().'tests/cli/UnitCept.php');
|
||||
$this->assertContains('$I->seeInThisFile', $code);
|
||||
$this->parser->parseSteps($code);
|
||||
$text = $this->scenario->getText();
|
||||
$this->assertContains("I see in this file", $text);
|
||||
}
|
||||
|
||||
public function testStepsWithFriends()
|
||||
{
|
||||
$code = file_get_contents(\Codeception\Configuration::projectDir().'tests/web/FriendsCept.php');
|
||||
$this->assertContains('$I->haveFriend', $code);
|
||||
$this->parser->parseSteps($code);
|
||||
$text = $this->scenario->getText();
|
||||
$this->assertContains("jon does", $text);
|
||||
$this->assertContains("I have friend", $text);
|
||||
$this->assertContains("back to me", $text);
|
||||
}
|
||||
|
||||
public function testParseFile()
|
||||
{
|
||||
$classes = Parser::getClassesFromFile(codecept_data_dir('SimpleTest.php'));
|
||||
$this->assertEquals(['SampleTest'], $classes);
|
||||
}
|
||||
|
||||
public function testParseFileWithClass()
|
||||
{
|
||||
if (version_compare(PHP_VERSION, '5.5.0', '<')) {
|
||||
$this->markTestSkipped('only for php 5.5');
|
||||
}
|
||||
$classes = Parser::getClassesFromFile(codecept_data_dir('php55Test'));
|
||||
$this->assertEquals(['php55Test'], $classes);
|
||||
}
|
||||
|
||||
public function testParseFileWithAnonymousClass()
|
||||
{
|
||||
if (version_compare(PHP_VERSION, '7.0.0', '<')) {
|
||||
$this->markTestSkipped('only for php 7');
|
||||
}
|
||||
$classes = Parser::getClassesFromFile(codecept_data_dir('php70Test'));
|
||||
$this->assertEquals(['php70Test'], $classes);
|
||||
}
|
||||
|
||||
/*
|
||||
* https://github.com/Codeception/Codeception/issues/1779
|
||||
*/
|
||||
public function testParseFileWhichUnsetsFileVariable()
|
||||
{
|
||||
$classes = Parser::getClassesFromFile(codecept_data_dir('unsetFile.php'));
|
||||
$this->assertEquals([], $classes);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group core
|
||||
* @throws \Codeception\Exception\TestParseException
|
||||
*/
|
||||
public function testModernValidation()
|
||||
{
|
||||
if (PHP_MAJOR_VERSION < 7) {
|
||||
$this->markTestSkipped();
|
||||
}
|
||||
$this->setExpectedException('Codeception\Exception\TestParseException');
|
||||
Parser::load(codecept_data_dir('Invalid.php'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group core
|
||||
*/
|
||||
public function testClassesFromFile()
|
||||
{
|
||||
$classes = Parser::getClassesFromFile(codecept_data_dir('DummyClass.php'));
|
||||
$this->assertContains('DummyClass', $classes);
|
||||
$classes = Parser::getClassesFromFile(codecept_data_dir('SimpleWithDependencyInjectionCest.php'));
|
||||
$this->assertContains('simpleDI\\LoadedTestWithDependencyInjectionCest', $classes);
|
||||
$this->assertContains('simpleDI\\AnotherCest', $classes);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user