Skip to content

Commit 3fecea9

Browse files
authored
Merge tests from codeception/yii2-tests to this repo (#56)
1 parent aec2976 commit 3fecea9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1323
-18
lines changed

Diff for: .gitattributes

+2
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@
44
/Robofile.php export-ignore
55
/*.md export-ignore
66
/*.yml export-ignore
7+
/tests export-ignore
8+
/.github export-ignore

Diff for: .github/workflows/main.yml

+2-16
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,7 @@ jobs:
2727
- name: Install dependencies
2828
run: composer install --prefer-dist --no-progress --no-interaction --no-suggest
2929

30-
- name: Checkout Yii2
31-
uses: actions/checkout@v2
32-
with:
33-
repository: Codeception/yii2-tests
34-
path: framework-tests
35-
36-
- name: Install Yii2
37-
run: |
38-
composer require --no-update codeception/module-asserts
39-
composer require --no-update codeception/module-filesystem
40-
composer require --no-update codeception/codeception
41-
composer update --no-dev --prefer-dist --no-interaction
42-
working-directory: framework-tests
43-
4430
- name: Run test suite
4531
run: |
46-
php vendor/bin/codecept build -c framework-tests
47-
php vendor/bin/codecept run -c framework-tests
32+
php vendor/bin/codecept build
33+
php vendor/bin/codecept run

Diff for: .gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
/.idea/
22
/vendor/
33
/composer.lock
4-
/framework-tests
4+
tests/_support
5+
tests/_output
6+
tests/cases/yii2-app-advanced/_data/db.sqlite

Diff for: codeception.yml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
paths:
2+
tests: tests
3+
output: tests/_output
4+
data: tests/_data
5+
support: tests/_support
6+
envs: tests/_envs
7+
modules:
8+
- Asserts
9+
bootstrap: bootstrap.php
10+
settings:
11+
colors: true
12+
memory_limit: 1024M
13+
include:
14+
- tests/cases/*

Diff for: composer.json

+21-1
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,30 @@
2222
"codeception/lib-innerbrowser": "^1.0",
2323
"codeception/codeception": "^4.0"
2424
},
25+
"require-dev": {
26+
"yiisoft/yii2": "dev-master",
27+
"yiisoft/yii2-app-advanced": "dev-master",
28+
"codeception/verify": "<2",
29+
"codemix/yii2-localeurls": "^1.7",
30+
"codeception/module-asserts": "^1.3",
31+
"codeception/module-filesystem": "^1.0"
32+
},
2533
"autoload":{
2634
"classmap": ["src/"]
2735
},
36+
"autoload-dev": {
37+
"classmap": [
38+
"vendor/yiisoft/yii2/Yii.php",
39+
"tests/cases"
40+
]
41+
},
2842
"config": {
2943
"classmap-authoritative": true
30-
}
44+
},
45+
"repositories": [
46+
{
47+
"type": "composer",
48+
"url": "https://asset-packagist.org"
49+
}
50+
]
3151
}

Diff for: tests/_data/.gitkeep

Whitespace-only changes.

Diff for: tests/bootstrap.php

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
defined('YII_DEBUG') || define('YII_DEBUG', true);
3+
defined('YII_ENV') || define('YII_ENV', 'test');
4+
5+
Yii::$container = new \yii\di\Container();
6+
7+
$link = __DIR__ . '/../vendor/yiisoft/yii2-app-advanced/vendor';
8+
if (!file_exists($link) && !symlink(__DIR__ . '/../vendor', $link)) {
9+
die('failed to create symlink');
10+
}

Diff for: tests/cases/closeConnections/codeception.yml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
paths:
2+
tests: .
3+
log: ../../_output
4+
data: _data
5+
support: ../../_support
6+
namespace: tests\
7+
modules:
8+
config:
9+
Yii2:
10+
configFile: config.php
11+
transaction: false
12+
cleanup: true

Diff for: tests/cases/closeConnections/config.php

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
return [
3+
'id' => 'Simple',
4+
'basePath' => __DIR__,
5+
6+
'components' => [
7+
'db' => [
8+
'class' => yii\db\Connection::class,
9+
'dsn' => 'sqlite:' . \tests\helpers\SqlliteHelper::getTmpFile(),
10+
],
11+
],
12+
];
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace tests\fixtures;
4+
5+
use yii\test\DbFixture;
6+
7+
class EmptyFixture extends DbFixture
8+
{
9+
public function load()
10+
{
11+
}
12+
13+
public function unload()
14+
{
15+
}
16+
}

Diff for: tests/cases/closeConnections/functional.suite.yml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
actor: FunctionalTester
2+
modules:
3+
enabled:
4+
- Yii2
5+
- Asserts
+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
namespace tests\closeConnections;
4+
5+
use Codeception\Example;
6+
use tests\fixtures\EmptyFixture;
7+
use tests\FunctionalTester;
8+
use tests\helpers\SqlliteHelper;
9+
10+
class FixturesCest
11+
{
12+
public function _fixtures()
13+
{
14+
return [
15+
[
16+
'class' => EmptyFixture::class,
17+
],
18+
];
19+
}
20+
21+
protected function numberProvider()
22+
{
23+
return array_pad([], 5, ['count' => 0]);
24+
}
25+
26+
/**
27+
* @param FunctionalTester $I
28+
* @dataProvider numberProvider
29+
*/
30+
public function NoConnections(FunctionalTester $I, Example $example)
31+
{
32+
$I->assertEquals(SqlliteHelper::connectionCount(), $example['count']);
33+
}
34+
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
namespace tests\closeConnections;
4+
5+
use Codeception\Example;
6+
use tests\fixtures\EmptyFixture;
7+
use tests\FunctionalTester;
8+
use tests\helpers\SqlliteHelper;
9+
10+
class FixturesInBeforeCest
11+
{
12+
public function _before(FunctionalTester $I)
13+
{
14+
$I->haveFixtures([
15+
[
16+
'class' => EmptyFixture::class,
17+
],
18+
]);
19+
}
20+
21+
protected function numberProvider()
22+
{
23+
return array_pad([], 5, ['count' => 1]);
24+
}
25+
26+
/**
27+
* @param FunctionalTester $I
28+
* @dataProvider numberProvider
29+
*/
30+
public function NoConnections(FunctionalTester $I, Example $example)
31+
{
32+
$I->assertEquals(SqlliteHelper::connectionCount(), $example['count']);
33+
}
34+
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace tests\closeConnections;
4+
5+
use Codeception\Example;
6+
use tests\FunctionalTester;
7+
use tests\helpers\SqlliteHelper;
8+
9+
class NoFixturesCest
10+
{
11+
12+
protected function numberProvider()
13+
{
14+
return array_pad([], 5, ['count' => 0]);
15+
}
16+
17+
/**
18+
* @param FunctionalTester $I
19+
* @dataProvider numberProvider
20+
*/
21+
public function NoConnections(FunctionalTester $I, Example $example)
22+
{
23+
$I->assertEquals(SqlliteHelper::connectionCount(), $example['count']);
24+
}
25+
}
+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace tests\helpers;
4+
5+
class SqlliteHelper
6+
{
7+
protected static $temp_name;
8+
9+
public static function getTmpFile()
10+
{
11+
if (empty(self::$temp_name)) {
12+
self::$temp_name = tempnam(null, '/file0');
13+
}
14+
return self::$temp_name;
15+
}
16+
17+
public static function connectionCount()
18+
{
19+
$path = self::$temp_name;
20+
$count = shell_exec("lsof -w {$path} | grep {$path} | wc -l");
21+
return (int)$count;
22+
}
23+
24+
public static function debug()
25+
{
26+
$path = self::$temp_name;
27+
$cmd = "lsof -w {$path}";
28+
codecept_debug("Executing : $cmd");
29+
codecept_debug(shell_exec($cmd));
30+
}
31+
32+
}
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
paths:
2+
tests: .
3+
log: ../../_output
4+
data: _data
5+
support: ../../_support
6+
namespace: tests\
7+
modules:
8+
config:
9+
Yii2:
10+
configFile: config.php
11+
transaction: false
12+
cleanup: false

Diff for: tests/cases/closeConnectionsNoCleanup/config.php

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
return [
3+
'id' => 'Simple',
4+
'basePath' => __DIR__,
5+
6+
'components' => [
7+
'db' => [
8+
'class' => yii\db\Connection::class,
9+
'dsn' => 'sqlite:' . \tests\helpers\SqlliteHelper::getTmpFile(),
10+
],
11+
],
12+
];
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
actor: FunctionalTester
2+
modules:
3+
enabled:
4+
- Yii2
5+
- Asserts
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
namespace tests\closeConnectionsNoCleanup;
4+
5+
use tests\FunctionalTester;
6+
use tests\fixtures\EmptyFixture;
7+
use tests\helpers\SqlliteHelper;
8+
9+
class FixturesCest
10+
{
11+
public function _fixtures()
12+
{
13+
return [
14+
[
15+
'class' => EmptyFixture::class,
16+
],
17+
];
18+
}
19+
20+
public function NoConnections1(FunctionalTester $I)
21+
{
22+
$count = SqlliteHelper::connectionCount();
23+
$I->assertEquals(0, $count);
24+
}
25+
26+
public function NoConnections2(FunctionalTester $I)
27+
{
28+
$count = SqlliteHelper::connectionCount();
29+
$I->assertEquals(0, $count);
30+
}
31+
32+
public function NoConnections3(FunctionalTester $I)
33+
{
34+
$count = SqlliteHelper::connectionCount();
35+
$I->assertEquals(0, $count);
36+
}
37+
38+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
namespace tests\closeConnectionsNoCleanup;
4+
5+
use tests\FunctionalTester;
6+
use tests\fixtures\EmptyFixture;
7+
use tests\helpers\SqlliteHelper;
8+
9+
class FixturesInBeforeCest
10+
{
11+
public function _before(FunctionalTester $I)
12+
{
13+
$I->haveFixtures([
14+
[
15+
'class' => EmptyFixture::class,
16+
],
17+
]);
18+
}
19+
20+
public function OnlyOneConnection1(FunctionalTester $I)
21+
{
22+
$count = SqlliteHelper::connectionCount();
23+
$I->assertEquals(1, $count);
24+
}
25+
26+
public function OnlyOneConnection2(FunctionalTester $I)
27+
{
28+
$count = SqlliteHelper::connectionCount();
29+
$I->assertEquals(1, $count);
30+
}
31+
32+
public function OnlyOneConnection3(FunctionalTester $I)
33+
{
34+
$count = SqlliteHelper::connectionCount();
35+
$I->assertEquals(1, $count);
36+
}
37+
}

0 commit comments

Comments
 (0)