ArrayHelperTest.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace fphammerle\yii2\auth\clientcert\tests;
  3. use \fphammerle\helpers\ArrayHelper;
  4. use \fphammerle\yii2\auth\clientcert\Authenticator;
  5. class ClientCertAuthTest extends \PHPUnit_Framework_TestCase
  6. {
  7. public function mockApplication()
  8. {
  9. $app = new \yii\web\Application([
  10. 'id' => 'yii2-client-cert-auth-test',
  11. 'basePath' => __DIR__,
  12. // 'vendorPath' => dirname(__DIR__) . '/vendor',
  13. 'components' => [
  14. 'db' => [
  15. 'class' => '\yii\db\Connection',
  16. 'dsn' => 'sqlite::memory:',
  17. ],
  18. 'user' => [
  19. 'identityClass' => models\User::className(),
  20. ],
  21. ],
  22. ]);
  23. $this->assertEquals([], $app->db->getSchema()->getTableNames());
  24. (new migrations\CreateUserTable)->up();
  25. $this->assertNull($app->user->getIdentity());
  26. return $app;
  27. }
  28. public function testCreateUser()
  29. {
  30. $app = $this->mockApplication();
  31. (new models\User('a'))->save();
  32. (new models\User('b'))->save();
  33. $users = ArrayHelper::map(
  34. models\User::find()->all(),
  35. function($u) { return $u->getAttributes(); }
  36. );
  37. $this->assertEquals(2, sizeof($users));
  38. $this->assertContains(['id' => 1, 'username' => 'a'], $users);
  39. $this->assertContains(['id' => 2, 'username' => 'b'], $users);
  40. }
  41. }