Skip to content
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

Merge tests repo #56

Merged
merged 12 commits into from
Nov 26, 2021
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
/Robofile.php export-ignore
/*.md export-ignore
/*.yml export-ignore
/tests export-ignore
/.github export-ignore
18 changes: 2 additions & 16 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,7 @@ jobs:
- name: Install dependencies
run: composer install --prefer-dist --no-progress --no-interaction --no-suggest

- name: Checkout Yii2
uses: actions/checkout@v2
with:
repository: Codeception/yii2-tests
path: framework-tests

- name: Install Yii2
run: |
composer require --no-update codeception/module-asserts
composer require --no-update codeception/module-filesystem
composer require --no-update codeception/codeception
composer update --no-dev --prefer-dist --no-interaction
working-directory: framework-tests

- name: Run test suite
run: |
php vendor/bin/codecept build -c framework-tests
php vendor/bin/codecept run -c framework-tests
php vendor/bin/codecept build
php vendor/bin/codecept run
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/.idea/
/vendor/
/composer.lock
/framework-tests
tests/_support
tests/_output
tests/cases/yii2-app-advanced/_data/db.sqlite
14 changes: 14 additions & 0 deletions codeception.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
paths:
tests: tests
output: tests/_output
data: tests/_data
support: tests/_support
envs: tests/_envs
modules:
- Asserts
bootstrap: bootstrap.php
settings:
colors: true
memory_limit: 1024M
include:
- tests/cases/*
22 changes: 21 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,30 @@
"codeception/lib-innerbrowser": "^1.0",
"codeception/codeception": "^4.0"
},
"require-dev": {
"yiisoft/yii2": "dev-master",
"yiisoft/yii2-app-advanced": "dev-master",
"codeception/verify": "<2",
"codemix/yii2-localeurls": "^1.7",
"codeception/module-asserts": "^1.3",
"codeception/module-filesystem": "^1.0"
},
"autoload":{
"classmap": ["src/"]
},
"autoload-dev": {
"classmap": [
"vendor/yiisoft/yii2/Yii.php",
"tests/cases"
]
},
"config": {
"classmap-authoritative": true
}
},
"repositories": [
{
"type": "composer",
"url": "https://asset-packagist.org"
}
]
}
Empty file added tests/_data/.gitkeep
Empty file.
10 changes: 10 additions & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php
defined('YII_DEBUG') || define('YII_DEBUG', true);
defined('YII_ENV') || define('YII_ENV', 'test');

Yii::$container = new \yii\di\Container();

$link = __DIR__ . '/../vendor/yiisoft/yii2-app-advanced/vendor';
if (!file_exists($link) && !symlink(__DIR__ . '/../vendor', $link)) {
die('failed to create symlink');
}
12 changes: 12 additions & 0 deletions tests/cases/closeConnections/codeception.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
paths:
tests: .
log: ../../_output
data: _data
support: ../../_support
namespace: tests\
modules:
config:
Yii2:
configFile: config.php
transaction: false
cleanup: true
12 changes: 12 additions & 0 deletions tests/cases/closeConnections/config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
return [
'id' => 'Simple',
'basePath' => __DIR__,

'components' => [
'db' => [
'class' => yii\db\Connection::class,
'dsn' => 'sqlite:' . \tests\helpers\SqlliteHelper::getTmpFile(),
],
],
];
16 changes: 16 additions & 0 deletions tests/cases/closeConnections/fixtures/EmptyFixture.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace tests\fixtures;

use yii\test\DbFixture;

class EmptyFixture extends DbFixture
{
public function load()
{
}

public function unload()
{
}
}
5 changes: 5 additions & 0 deletions tests/cases/closeConnections/functional.suite.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
actor: FunctionalTester
modules:
enabled:
- Yii2
- Asserts
35 changes: 35 additions & 0 deletions tests/cases/closeConnections/functional/FixturesCest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace tests\closeConnections;

use Codeception\Example;
use tests\fixtures\EmptyFixture;
use tests\FunctionalTester;
use tests\helpers\SqlliteHelper;

class FixturesCest
{
public function _fixtures()
{
return [
[
'class' => EmptyFixture::class,
],
];
}

protected function numberProvider()
{
return array_pad([], 5, ['count' => 0]);
}

/**
* @param FunctionalTester $I
* @dataProvider numberProvider
*/
public function NoConnections(FunctionalTester $I, Example $example)
{
$I->assertEquals(SqlliteHelper::connectionCount(), $example['count']);
}

}
35 changes: 35 additions & 0 deletions tests/cases/closeConnections/functional/FixturesInBeforeCest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace tests\closeConnections;

use Codeception\Example;
use tests\fixtures\EmptyFixture;
use tests\FunctionalTester;
use tests\helpers\SqlliteHelper;

class FixturesInBeforeCest
{
public function _before(FunctionalTester $I)
{
$I->haveFixtures([
[
'class' => EmptyFixture::class,
],
]);
}

protected function numberProvider()
{
return array_pad([], 5, ['count' => 1]);
}

/**
* @param FunctionalTester $I
* @dataProvider numberProvider
*/
public function NoConnections(FunctionalTester $I, Example $example)
{
$I->assertEquals(SqlliteHelper::connectionCount(), $example['count']);
}

}
25 changes: 25 additions & 0 deletions tests/cases/closeConnections/functional/NoFixturesCest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace tests\closeConnections;

use Codeception\Example;
use tests\FunctionalTester;
use tests\helpers\SqlliteHelper;

class NoFixturesCest
{

protected function numberProvider()
{
return array_pad([], 5, ['count' => 0]);
}

/**
* @param FunctionalTester $I
* @dataProvider numberProvider
*/
public function NoConnections(FunctionalTester $I, Example $example)
{
$I->assertEquals(SqlliteHelper::connectionCount(), $example['count']);
}
}
32 changes: 32 additions & 0 deletions tests/cases/closeConnections/helpers/SqlliteHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace tests\helpers;

class SqlliteHelper
{
protected static $temp_name;

public static function getTmpFile()
{
if (empty(self::$temp_name)) {
self::$temp_name = tempnam(null, '/file0');
}
return self::$temp_name;
}

public static function connectionCount()
{
$path = self::$temp_name;
$count = shell_exec("lsof -w {$path} | grep {$path} | wc -l");
return (int)$count;
}

public static function debug()
{
$path = self::$temp_name;
$cmd = "lsof -w {$path}";
codecept_debug("Executing : $cmd");
codecept_debug(shell_exec($cmd));
}

}
12 changes: 12 additions & 0 deletions tests/cases/closeConnectionsNoCleanup/codeception.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
paths:
tests: .
log: ../../_output
data: _data
support: ../../_support
namespace: tests\
modules:
config:
Yii2:
configFile: config.php
transaction: false
cleanup: false
12 changes: 12 additions & 0 deletions tests/cases/closeConnectionsNoCleanup/config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
return [
'id' => 'Simple',
'basePath' => __DIR__,

'components' => [
'db' => [
'class' => yii\db\Connection::class,
'dsn' => 'sqlite:' . \tests\helpers\SqlliteHelper::getTmpFile(),
],
],
];
5 changes: 5 additions & 0 deletions tests/cases/closeConnectionsNoCleanup/functional.suite.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
actor: FunctionalTester
modules:
enabled:
- Yii2
- Asserts
38 changes: 38 additions & 0 deletions tests/cases/closeConnectionsNoCleanup/functional/FixturesCest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace tests\closeConnectionsNoCleanup;

use tests\FunctionalTester;
use tests\fixtures\EmptyFixture;
use tests\helpers\SqlliteHelper;

class FixturesCest
{
public function _fixtures()
{
return [
[
'class' => EmptyFixture::class,
],
];
}

public function NoConnections1(FunctionalTester $I)
{
$count = SqlliteHelper::connectionCount();
$I->assertEquals(0, $count);
}

public function NoConnections2(FunctionalTester $I)
{
$count = SqlliteHelper::connectionCount();
$I->assertEquals(0, $count);
}

public function NoConnections3(FunctionalTester $I)
{
$count = SqlliteHelper::connectionCount();
$I->assertEquals(0, $count);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace tests\closeConnectionsNoCleanup;

use tests\FunctionalTester;
use tests\fixtures\EmptyFixture;
use tests\helpers\SqlliteHelper;

class FixturesInBeforeCest
{
public function _before(FunctionalTester $I)
{
$I->haveFixtures([
[
'class' => EmptyFixture::class,
],
]);
}

public function OnlyOneConnection1(FunctionalTester $I)
{
$count = SqlliteHelper::connectionCount();
$I->assertEquals(1, $count);
}

public function OnlyOneConnection2(FunctionalTester $I)
{
$count = SqlliteHelper::connectionCount();
$I->assertEquals(1, $count);
}

public function OnlyOneConnection3(FunctionalTester $I)
{
$count = SqlliteHelper::connectionCount();
$I->assertEquals(1, $count);
}
}