Browse Source

tests: mock yii2 app and test db connection

Fabian Peter Hammerle 8 years ago
parent
commit
465f372d6d
3 changed files with 23 additions and 3 deletions
  1. 1 1
      ClientCertAuth.php
  2. 2 1
      composer.json
  3. 20 1
      tests/ArrayHelperTest.php

+ 1 - 1
ClientCertAuth.php

@@ -2,7 +2,7 @@
 
 namespace fphammerle\yii2;
 
-class ClientCertAuth
+class ClientCertAuth extends \yii\base\Component
 {
     /**
      * @return string

+ 2 - 1
composer.json

@@ -8,7 +8,8 @@
         }
     ],
     "require": {
-        "php": ">=5.4.0"
+        "php": ">=5.4.0",
+        "yiisoft/yii2": "^2.0"
     },
     "require-dev": {
         "phpunit/phpunit": "4.8.*"

+ 20 - 1
tests/ArrayHelperTest.php

@@ -4,8 +4,27 @@ use fphammerle\yii2\ClientCertAuth;
 
 class ClientCertAuthTest extends \PHPUnit_Framework_TestCase
 {
-    public function testFlattenEmpty()
+    public function mockApplication()
     {
+        return new \yii\web\Application([
+            'id' => 'yii2-client-cert-auth-test',
+            'basePath' => __DIR__,
+            // 'vendorPath' => dirname(__DIR__) . '/vendor',
+            'components' => [
+                'db' => [
+                    'class' => '\yii\db\Connection',
+                    'dsn' => 'sqlite::memory:',
+                ],
+            ],
+        ]);
+    }
+
+    public function testDb()
+    {
+        $app = $this->mockApplication();
+        $app->db->createCommand('CREATE TABLE test ( x INT )')->execute();
+        $app->db->createCommand('INSERT INTO test (x) VALUES (1), (2), (4)')->execute();
+        var_dump($app->db->createCommand('SELECT * FROM test')->queryAll());
         $this->assertEquals('bar', ClientCertAuth::foo());
     }
 }