浏览代码

added Subject model

Fabian Peter Hammerle 8 年之前
父节点
当前提交
9a12641634
共有 3 个文件被更改,包括 73 次插入0 次删除
  1. 26 0
      Subject.php
  2. 20 0
      migrations/CreateSubjectTable.php
  3. 27 0
      tests/SubjectTest.php

+ 26 - 0
Subject.php

@@ -0,0 +1,26 @@
+<?php
+
+namespace fphammerle\yii2\auth\clientcert;
+
+class Subject extends \yii\db\ActiveRecord
+{
+    public static function tableName()
+    {
+        return 'identity_cert_subject';
+    }
+
+    // public function getIdentityId()
+    // {
+    //     return $this->identity_id;
+    // }
+
+    // public static function getIdentityClass()
+    // {
+    //     return \Yii::$app->user->identityClass;
+    // }
+    //
+    // public function getIdentity()
+    // {
+    //     return $this->hasOne(self::getIdentityClass(), ['id' => 'identity_id']);
+    // }
+}

+ 20 - 0
migrations/CreateSubjectTable.php

@@ -0,0 +1,20 @@
+<?php
+
+namespace fphammerle\yii2\auth\clientcert\migrations;
+
+use fphammerle\yii2\auth\clientcert\Subject;
+
+class CreateSubjectTable extends \yii\db\Migration
+{
+    public function safeUp()
+    {
+        $this->createTable(Subject::tableName(), [
+            'id' => $this->primaryKey(),
+        ]);
+    }
+
+    public function safeDown()
+    {
+        $this->dropTable(Subject::tableName());
+    }
+}

+ 27 - 0
tests/SubjectTest.php

@@ -0,0 +1,27 @@
+<?php
+
+namespace fphammerle\yii2\auth\clientcert\tests;
+
+use \fphammerle\helpers\ArrayHelper;
+use \fphammerle\yii2\auth\clientcert\Subject;
+use \fphammerle\yii2\auth\clientcert\migrations;
+
+class SubjectTest extends TestCase
+{
+    public function testCreateModel()
+    {
+        $app = $this->mockApplication();
+        (new migrations\CreateSubjectTable)->up();
+        (new Subject())->save();
+        (new Subject())->save();
+        (new Subject())->save();
+        $subjects = ArrayHelper::map(
+            Subject::find()->all(),
+            function($s) { return $s->getAttributes(); }
+        );
+        $this->assertEquals(3, sizeof($subjects));
+        $this->assertContains(['id' => 1], $subjects);
+        $this->assertContains(['id' => 2], $subjects);
+        $this->assertContains(['id' => 3], $subjects);
+    }
+}