Skip to content
This repository was archived by the owner on Aug 15, 2018. It is now read-only.

Commit 8284852

Browse files
committed
Structure files
1 parent f308f65 commit 8284852

File tree

10 files changed

+185
-0
lines changed

10 files changed

+185
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
/composer.lock
33
*.swp
44
/.idea
5+
/tests/config-local.php

Cache.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespace dcb9\redis;
4+
5+
class Cache extends \yii\caching\Cache
6+
{
7+
8+
}

Connection.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace dcb9\redis;
4+
5+
use yii\base\Component;
6+
7+
class Connection extends Component
8+
{
9+
10+
}

Session.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespace dcb9\redis;
4+
5+
class Session extends \yii\web\Session
6+
{
7+
8+
}

phpunit.xml.dist

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<phpunit bootstrap="./tests/bootstrap.php"
3+
colors="true"
4+
convertErrorsToExceptions="true"
5+
convertNoticesToExceptions="true"
6+
convertWarningsToExceptions="true"
7+
stopOnFailure="false">
8+
<testsuites>
9+
<testsuite name="Test Suite">
10+
<directory>./tests</directory>
11+
</testsuite>
12+
</testsuites>
13+
</phpunit>

tests/CacheTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespace dcb9\redis\tests;
4+
5+
class CacheTest extends TestCase
6+
{
7+
8+
}

tests/ConnectionTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace dcb9\redis\tests;
4+
5+
class ConnectionTest extends TestCase
6+
{
7+
}

tests/TestCase.php

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
<?php
2+
3+
namespace dcb9\redis\tests;
4+
5+
use yii\di\Container;
6+
use yii\helpers\ArrayHelper;
7+
use Yii;
8+
use dcb9\redis\Connection;
9+
10+
/**
11+
* This is the base class for all yii framework unit tests.
12+
*/
13+
abstract class TestCase extends \PHPUnit_Framework_TestCase
14+
{
15+
public static $params;
16+
17+
/**
18+
* Returns a test configuration param from config.php or config-local.php
19+
* @return array the value of the configuration param
20+
*/
21+
public static function getParam()
22+
{
23+
if (static::$params === null) {
24+
if (file_exists(__DIR__ . '/config-local.php')) {
25+
static::$params = include(__DIR__ . '/config-local.php');
26+
} else {
27+
static::$params = include(__DIR__ . '/config.php');
28+
}
29+
}
30+
31+
return static::$params;
32+
}
33+
34+
/**
35+
* Clean up after test.
36+
* By default the application created with [[mockApplication]] will be destroyed.
37+
*/
38+
protected function tearDown()
39+
{
40+
parent::tearDown();
41+
$this->destroyApplication();
42+
}
43+
44+
/**
45+
* Populates Yii::$app with a new application
46+
* The application will be destroyed on tearDown() automatically.
47+
* @param array $config The application configuration, if needed
48+
* @param string $appClass name of the application class to create
49+
*/
50+
protected function mockApplication($config = [], $appClass = '\yii\console\Application')
51+
{
52+
new $appClass(ArrayHelper::merge([
53+
'id' => 'testapp',
54+
'basePath' => __DIR__,
55+
'vendorPath' => dirname(__DIR__) . '/vendor',
56+
], $config));
57+
}
58+
59+
protected function mockWebApplication($config = [], $appClass = '\yii\web\Application')
60+
{
61+
new $appClass(ArrayHelper::merge([
62+
'id' => 'testapp',
63+
'basePath' => __DIR__,
64+
'vendorPath' => dirname(__DIR__) . '/vendor',
65+
'components' => [
66+
'request' => [
67+
'cookieValidationKey' => 'wefJDF8sfdsfSDefwqdxj9oq',
68+
'scriptFile' => __DIR__ . '/index.php',
69+
'scriptUrl' => '/index.php',
70+
],
71+
]
72+
], $config));
73+
}
74+
75+
/**
76+
* Destroys application in Yii::$app by setting it to null.
77+
*/
78+
protected function destroyApplication()
79+
{
80+
Yii::$app = null;
81+
Yii::$container = new Container();
82+
}
83+
84+
protected function setUp()
85+
{
86+
$params = self::getParam();
87+
if ($params === null) {
88+
$this->markTestSkipped('No redis server connection configured.');
89+
}
90+
$connection = new Connection($params);
91+
$this->mockApplication(['components' => ['redis' => $connection]]);
92+
93+
parent::setUp();
94+
}
95+
96+
/**
97+
* @param boolean $reset whether to clean up the test database
98+
* @return Connection
99+
*/
100+
public function getConnection($reset = true)
101+
{
102+
$params = self::getParam();
103+
$db = new Connection($params);
104+
if ($reset) {
105+
$db->open();
106+
$db->flushdb();
107+
}
108+
109+
return $db;
110+
}
111+
}

tests/bootstrap.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
// ensure we get report on all possible php errors
4+
error_reporting(-1);
5+
define('YII_ENABLE_ERROR_HANDLER', false);
6+
define('YII_DEBUG', true);
7+
8+
$_SERVER['SCRIPT_NAME'] = '/' . __DIR__;
9+
$_SERVER['SCRIPT_FILENAME'] = __FILE__;
10+
require_once(__DIR__ . '/../vendor/autoload.php');
11+
require_once(__DIR__ . '/../vendor/yiisoft/yii2/Yii.php');

tests/config.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
return [
4+
'hostname' => 'localhost',
5+
'port' => 6379,
6+
'database' => 0,
7+
'password' => null,
8+
];

0 commit comments

Comments
 (0)