<NME> TokenTokenTest.php
<BEF> <?php

namespace Bolt\Tests\AccessControl;

use Bolt\AccessControl\Token\Token;
use Bolt\Storage\Entity;
use Bolt\Tests\BoltUnitTest;

/**
 * Test for AccessControl\Token\Token.
 *
 * @author Gawain Lynch <gawain.lynch@gmail.com>
 */
class TokenTokenTest extends BoltUnitTest
{
    public function testConstructor()
    {
        $userEntity = new Entity\Users();
        $tokenEntity = new Entity\Authtoken();
        $token = new Token($userEntity, $tokenEntity);

        $this->assertInstanceOf(Token::class, $token);
    }

    public function testStringCast()
    {
        $userEntity = new Entity\Users();
        $tokenEntity = new Entity\Authtoken(['token' => 'cookies']);
        $token = new Token($userEntity, $tokenEntity);

        $this->assertInstanceOf(Token::class, $token);
        $this->assertSame('cookies', (string) $token);
    }

    public function testIsEnabled()
    {
        $userEntity = new Entity\Users(['enabled' => true]);
        $tokenEntity = new Entity\Authtoken();
        $token = new Token($userEntity, $tokenEntity);

        $this->assertInstanceOf(Token::class, $token);
        $this->assertTrue($token->isEnabled());

        $userEntity = new Entity\Users(['enabled' => false]);
        $tokenEntity = new Entity\Authtoken();
        $token = new Token($userEntity, $tokenEntity);

        $this->assertInstanceOf(Token::class, $token);
        $this->assertFalse($token->isEnabled());
    }

    public function testGetUser()
    {
        $userEntity = new Entity\Users(['username' => 'koala']);
        $tokenEntity = new Entity\Authtoken();
        $token = new Token($userEntity, $tokenEntity);
        $user = $token->getUser();
        $this->assertInstanceOf('Bolt\Storage\Entity\Users', $user);
        $this->assertSame('koala', $user->getUsername());
    }
}
    }

    public function testGetToken()
    {
        $userEntity = new Entity\Users();
        $tokenEntity = new Entity\Authtoken(['token' => 'gum-leaves']);
        $token = new Token($userEntity, $tokenEntity);
        $authToken = $token->getToken();

        $this->assertInstanceOf(Token::class, $token);
        $this->assertInstanceOf(Entity\AuthToken::class, $authToken);
        $this->assertSame('gum-leaves', $authToken->getToken());
    }

    public function testSetToken()
    {
        $userEntity = new Entity\Users();
        $tokenEntity = new Entity\Authtoken(['token' => 'gum-leaves']);
        $token = new Token($userEntity, $tokenEntity);

        $this->assertInstanceOf(Token::class, $token);

        $tokenEntity = new Entity\Authtoken(['token' => 'cookies']);
        $token->setToken($tokenEntity);

        $authToken = $token->getToken();

        $this->assertInstanceOf(Entity\Authtoken::class, $authToken);
        $this->assertSame('cookies', $authToken->getToken());
    }

    public function testGetChecked()
    {
        $userEntity = new Entity\Users();
        $tokenEntity = new Entity\Authtoken();
        $token = new Token($userEntity, $tokenEntity);

        $this->assertInstanceOf(Token::class, $token);

        $checked = $token->getChecked();
        $this->assertGreaterThan(time() - 1, $checked);
        $this->assertLessThanOrEqual(time(), $checked);
    }

    public function testSetChecked()
    {
        $userEntity = new Entity\Users();
        $tokenEntity = new Entity\Authtoken();
        $token = new Token($userEntity, $tokenEntity);

        $this->assertInstanceOf(Token::class, $token);

        $token->setChecked();
        $checked = $token->getChecked();
        $this->assertGreaterThan(time() - 1, $checked);
        $this->assertLessThanOrEqual(time(), $checked);
    }
}

<MSG> [Tests] Token\Token::setUser()
<DFF> @@ -58,4 +58,21 @@ class TokenTokenTest extends BoltUnitTest
         $this->assertInstanceOf('Bolt\Storage\Entity\Users', $user);
         $this->assertSame('koala', $user->getUsername());
     }
+
+    public function testSetUser()
+    {
+        $userEntity = new Entity\Users(['username' => 'koala']);
+        $tokenEntity = new Entity\Authtoken();
+        $token = new Token($userEntity, $tokenEntity);
+
+        $this->assertInstanceOf('Bolt\AccessControl\Token\Token', $token);
+
+        $userEntity = new Entity\Users(['username' => 'clippy']);
+        $token->setUser($userEntity);
+
+        $user = $token->getUser();
+
+        $this->assertInstanceOf('Bolt\Storage\Entity\Users', $user);
+        $this->assertSame('clippy', $user->getUsername());
+    }
 }

{'commit': "diff --git a/tests/phpunit/unit/AccessControl/TokenTokenTest.php b/tests/phpunit/unit/AccessControl/TokenTokenTest.php\nindex 096dd90b9..cb14488c2 100644\n--- a/tests/phpunit/unit/AccessControl/TokenTokenTest.php\n+++ b/tests/phpunit/unit/AccessControl/TokenTokenTest.php\n@@ -58,4 +58,21 @@ class TokenTokenTest extends BoltUnitTest\n         $this->assertInstanceOf('Bolt\\Storage\\Entity\\Users', $user);\n         $this->assertSame('koala', $user->getUsername());\n     }\n+\n+    public function testSetUser()\n+    {\n+        $userEntity = new Entity\\Users(['username' => 'koala']);\n+        $tokenEntity = new Entity\\Authtoken();\n+        $token = new Token($userEntity, $tokenEntity);\n+\n+        $this->assertInstanceOf('Bolt\\AccessControl\\Token\\Token', $token);\n+\n+        $userEntity = new Entity\\Users(['username' => 'clippy']);\n+        $token->setUser($userEntity);\n+\n+        $user = $token->getUser();\n+\n+        $this->assertInstanceOf('Bolt\\Storage\\Entity\\Users', $user);\n+        $this->assertSame('clippy', $user->getUsername());\n+    }\n }\n", 'commit_subject': '[Tests] Token\\Token::setUser()', 'repo_name': 'bolt/bolt', 'committer': {'name': 'Gawain Lynch', 'email': 'f745ec5336bcd096400627fc09f6ec7139408726@gmail.com', 'time_sec': '1444203065', 'tz_offset': '60', 'date': {'seconds': '1444203065'}}, 'commit_tree': '90fd71af45a74f5a0367c23598ed6588d333f0fd', 'commit_message': '[Tests] Token\\Token::setUser()', 'language_name': 'JavaScript', 'license': 'mit', 'hunks': "@@ -58,4 +58,21 @@ class TokenTokenTest extends BoltUnitTest\n         $this->assertInstanceOf('Bolt\\Storage\\Entity\\Users', $user);\n         $this->assertSame('koala', $user->getUsername());\n     }\n+\n+    public function testSetUser()\n+    {\n+        $userEntity = new Entity\\Users(['username' => 'koala']);\n+        $tokenEntity = new Entity\\Authtoken();\n+        $token = new Token($userEntity, $tokenEntity);\n+\n+        $this->assertInstanceOf('Bolt\\AccessControl\\Token\\Token', $token);\n+\n+        $userEntity = new Entity\\Users(['username' => 'clippy']);\n+        $token->setUser($userEntity);\n+\n+        $user = $token->getUser();\n+\n+        $this->assertInstanceOf('Bolt\\Storage\\Entity\\Users', $user);\n+        $this->assertSame('clippy', $user->getUsername());\n+    }\n }\n", 'addition_count': 17, 'deletion_count': 0, 'src_file': 'a/tests/phpunit/unit/AccessControl/TokenTokenTest.php', 'tgt_file': 'b/tests/phpunit/unit/AccessControl/TokenTokenTest.php', 'file_extension': '.php', 'before_file': "<?php\n\nnamespace Bolt\\Tests\\AccessControl;\n\nuse Bolt\\AccessControl\\Token\\Token;\nuse Bolt\\Storage\\Entity;\nuse Bolt\\Tests\\BoltUnitTest;\n\n/**\n * Test for AccessControl\\Token\\Token.\n *\n * @author Gawain Lynch <gawain.lynch@gmail.com>\n */\nclass TokenTokenTest extends BoltUnitTest\n{\n    public function testConstructor()\n    {\n        $userEntity = new Entity\\Users();\n        $tokenEntity = new Entity\\Authtoken();\n        $token = new Token($userEntity, $tokenEntity);\n\n        $this->assertInstanceOf(Token::class, $token);\n    }\n\n    public function testStringCast()\n    {\n        $userEntity = new Entity\\Users();\n        $tokenEntity = new Entity\\Authtoken(['token' => 'cookies']);\n        $token = new Token($userEntity, $tokenEntity);\n\n        $this->assertInstanceOf(Token::class, $token);\n        $this->assertSame('cookies', (string) $token);\n    }\n\n    public function testIsEnabled()\n    {\n        $userEntity = new Entity\\Users(['enabled' => true]);\n        $tokenEntity = new Entity\\Authtoken();\n        $token = new Token($userEntity, $tokenEntity);\n\n        $this->assertInstanceOf(Token::class, $token);\n        $this->assertTrue($token->isEnabled());\n\n        $userEntity = new Entity\\Users(['enabled' => false]);\n        $tokenEntity = new Entity\\Authtoken();\n        $token = new Token($userEntity, $tokenEntity);\n\n        $this->assertInstanceOf(Token::class, $token);\n        $this->assertFalse($token->isEnabled());\n    }\n\n    public function testGetUser()\n    {\n        $userEntity = new Entity\\Users(['username' => 'koala']);\n        $tokenEntity = new Entity\\Authtoken();\n        $token = new Token($userEntity, $tokenEntity);\n        $user = $token->getUser();\n        $this->assertInstanceOf('Bolt\\Storage\\Entity\\Users', $user);\n        $this->assertSame('koala', $user->getUsername());\n    }\n}\n    }\n\n    public function testGetToken()\n    {\n        $userEntity = new Entity\\Users();\n        $tokenEntity = new Entity\\Authtoken(['token' => 'gum-leaves']);\n        $token = new Token($userEntity, $tokenEntity);\n        $authToken = $token->getToken();\n\n        $this->assertInstanceOf(Token::class, $token);\n        $this->assertInstanceOf(Entity\\AuthToken::class, $authToken);\n        $this->assertSame('gum-leaves', $authToken->getToken());\n    }\n\n    public function testSetToken()\n    {\n        $userEntity = new Entity\\Users();\n        $tokenEntity = new Entity\\Authtoken(['token' => 'gum-leaves']);\n        $token = new Token($userEntity, $tokenEntity);\n\n        $this->assertInstanceOf(Token::class, $token);\n\n        $tokenEntity = new Entity\\Authtoken(['token' => 'cookies']);\n        $token->setToken($tokenEntity);\n\n        $authToken = $token->getToken();\n\n        $this->assertInstanceOf(Entity\\Authtoken::class, $authToken);\n        $this->assertSame('cookies', $authToken->getToken());\n    }\n\n    public function testGetChecked()\n    {\n        $userEntity = new Entity\\Users();\n        $tokenEntity = new Entity\\Authtoken();\n        $token = new Token($userEntity, $tokenEntity);\n\n        $this->assertInstanceOf(Token::class, $token);\n\n        $checked = $token->getChecked();\n        $this->assertGreaterThan(time() - 1, $checked);\n        $this->assertLessThanOrEqual(time(), $checked);\n    }\n\n    public function testSetChecked()\n    {\n        $userEntity = new Entity\\Users();\n        $tokenEntity = new Entity\\Authtoken();\n        $token = new Token($userEntity, $tokenEntity);\n\n        $this->assertInstanceOf(Token::class, $token);\n\n        $token->setChecked();\n        $checked = $token->getChecked();\n        $this->assertGreaterThan(time() - 1, $checked);\n        $this->assertLessThanOrEqual(time(), $checked);\n    }\n}\n", 'message': '[Tests] Token\\Token::setUser()', 'author_name': 'Gawain Lynch', 'lang': 'php'}