<NME> BoltUnitTest.php
<BEF> <?php

namespace Bolt\Tests;

use Bolt;
use Bolt\AccessControl\AccessChecker;
use Bolt\AccessControl\Login;
use Bolt\AccessControl\Permissions;
use Bolt\AccessControl\Token;
use Bolt\Configuration as Config;
use Bolt\Legacy\Storage;
use Bolt\Logger\FlashLogger;
use Bolt\Logger\Manager;
use Bolt\Storage\Entity;
use Bolt\Tests\Mocks\ImageApiMock;
use Bolt\Tests\Mocks\LoripsumMock;
use Bolt\Users;
use Doctrine\Common\Cache\VoidCache;
use GuzzleHttp\Client;
use Monolog\Logger;
use PHPUnit\Framework\TestCase;
use PHPUnit_Framework_MockObject_MockObject as MockObject;
use Silex\Application;
use Swift_Mailer;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
use Symfony\Component\Security\Csrf\CsrfTokenManager;
use Symfony\Component\Security\Csrf\TokenStorage\SessionTokenStorage;

/**
 * Abstract Class that other unit tests can extend, provides generic methods for Bolt tests.
 *
 * @author Ross Riley <riley.ross@gmail.com>
 **/
abstract class BoltUnitTest extends TestCase
{
    /** @var \Silex\Application|\Bolt\Application */
    private $app;

    protected function resetDb()
    {
        // Make sure we wipe the db file to start with a clean one
        if (is_readable(PHPUNIT_WEBROOT . '/app/database/bolt.db')) {
            unlink(PHPUNIT_WEBROOT . '/app/database/bolt.db');
            copy(PHPUNIT_ROOT . '/resources/db/bolt.db', PHPUNIT_WEBROOT . '/app/database/bolt.db');
        }
    }

    protected function resetConfig()
    {
        $configFiles = [
            'config.yml',
            'contenttypes.yml',
            'menu.yml',
            'permissions.yml',
            'routing.yml',
            'taxonomy.yml',
        ];
        foreach ($configFiles as $configFile) {
            // Make sure we wipe the db file to start with a clean one
            if (is_readable(PHPUNIT_WEBROOT . '/app/config/' . $configFile)) {
                unlink(PHPUNIT_WEBROOT . '/app/config/' . $configFile);
            }
        }
        if (is_readable(PHPUNIT_WEBROOT . '/app/cache/config-cache.json')) {
            unlink(PHPUNIT_WEBROOT . '/app/cache/config-cache.json');
        }
    }

    /**
     * @param bool $boot
     *
     * @return \Silex\Application
     */
    protected function getApp($boot = true)
    {
        if (!$this->app) {
            $this->app = $this->makeApp();
            $this->app->initialize();

            $verifier = new Config\Validation\Validator(
                $this->app['config'],
                $this->app['path_resolver'],
                $this->app['logger.flash']
            );
            $verifier->checks();

            if ($boot) {
                $this->app->boot();
                $this->app->flush();
            }
        }

        return $this->app;
    }

    /**
     * @return \Silex\Application
     */
    protected function makeApp()
    {
        $app = new Bolt\Application();
        $app['path_resolver.root'] = PHPUNIT_WEBROOT;
        $app['path_resolver.paths'] = ['web' => '.'];
        $app['debug'] = false;

        $app['config']->set(
            'general/database',
            [
                'driver'       => 'pdo_sqlite',
                'prefix'       => 'bolt_',
                'user'         => 'test',
                'path'         => PHPUNIT_WEBROOT . '/app/database/bolt.db',
                'wrapperClass' => '\Bolt\Storage\Database\Connection',
            ]
        );

        return $app;
    }

    protected function rmdir($dir)
    {
        if (!is_dir($dir)) {
            return;
        }
        $iterator = new \RecursiveIteratorIterator(
            new \RecursiveDirectoryIterator($dir, \FilesystemIterator::SKIP_DOTS),
            \RecursiveIteratorIterator::CHILD_FIRST
        );
        foreach ($iterator as $file) {
            if ($file->isDir()) {
                rmdir($file->getPathname());
            } else {
                unlink($file->getPathname());
            }
        }
        rmdir($dir);
    }

    protected function addDefaultUser(Application $app)
    {
        // Check if default user exists before adding
        $existingUser = $app['users']->getUser('admin');
        if ($existingUser !== false) {
            return $existingUser;
        }

        $user = [
            'username'    => 'admin',
            'password'    => 'password',
            'email'       => 'admin@example.com',
            'displayname' => 'Admin',
            'roles'       => ['admin'],
            'enabled'     => true,
        ];

        $app['users']->saveUser(array_merge($app['users']->getEmptyUser(), $user));
            'utils'  => $app->share(function () use ($app) { return new UtilsHandler($app); }),
        ));
    }
}
    }

    protected function allowLogin($app)
    {
        $this->addDefaultUser($app);
        $users = $this->getMockUsers(['isEnabled']);
        $users->expects($this->any())
            ->method('isEnabled')
            ->will($this->returnValue(true));
        $this->setService('users', $users);

        $permissions = $this->getMockPermissions(['isAllowed']);
        $permissions->expects($this->any())
            ->method('isAllowed')
            ->will($this->returnValue(true));
        $this->setService('permissions', $permissions);

        $auth = $this->getMockAccessChecker($app);
        $auth->expects($this->any())
            ->method('isValidSession')
            ->will($this->returnValue(true));

        $this->setService('access_control', $auth);
    }

    protected function removeCSRF($app)
    {
        // Symfony forms need a CSRF token so we have to mock this too
        $csrf = $this->getMockCsrfTokenManager(['isTokenValid', 'getToken']);
        $csrf->expects($this->any())
            ->method('isTokenValid')
            ->will($this->returnValue(true));

        $csrf->expects($this->any())
            ->method('getToken')
            ->will($this->returnValue('xyz'));

        $this->setService('form.csrf_provider', $csrf);
    }

    /**
     * @param array $contentTypes
     * @param array $categories
     * @param int   $count
     */
    protected function addSomeContent($contentTypes = null, $categories = null, $count = null)
    {
        $contentTypes = $contentTypes ?: ['showcases', 'pages', 'homepage'];
        $categories = $categories ?: ['news'];
        $count = $count ?: 5;

        $app = $this->getApp();
        $this->addDefaultUser($app);
        $app['config']->set('taxonomy/categories/options', $categories);
        $this->setService('prefill', new LoripsumMock());
        $this->setService('prefill.image', new ImageApiMock());

        $builder = $app['prefill.builder'];
        $builder->build($contentTypes, $count);
    }

    /**
     * @param string $key
     * @param mixed  $value
     */
    protected function setService($key, $value)
    {
        // In Pimple v3+ you can't re-set a container value,
        // this just keeps us working forward with tests.
        $this->getApp()->offsetUnset($key);
        $this->getApp()->offsetSet($key, $value);
    }

    protected function getService($key)
    {
        return $this->getApp()->offsetGet($key);
    }

    protected function setSessionUser(Entity\Users $userEntity)
    {
        $tokenEntity = new Entity\Authtoken();
        $tokenEntity->setToken('testtoken');
        $authToken = new Token\Token($userEntity, $tokenEntity);

        $this->getService('session')->set('authentication', $authToken);
    }

    /*
     * MOCKS
     */

    /**
     * @param \Silex\Application $app
     * @param array              $methods Defaults to ['isValidSession']
     *
     * @return \Bolt\AccessControl\AccessChecker|MockObject
     */
    protected function getMockAccessChecker($app, $methods = ['isValidSession'])
    {
        $parameters = [
            $app['storage.lazy'],
            $app['request_stack'],
            $app['session'],
            $app['dispatcher'],
            $app['logger.flash'],
            $app['logger.system'],
            $app['permissions'],
            $app['randomgenerator'],
            $app['access_control.cookie.options'],
        ];
        $accessCheckerMock = $this->getMockBuilder(AccessChecker::class)
            ->setMethods($methods)
            ->setConstructorArgs($parameters)
            ->getMock()
        ;

        return $accessCheckerMock;
    }

    /**
     * @return VoidCache|MockObject
     */
    protected function getMockCache()
    {
        return $this->getMockBuilder(VoidCache::class)
            ->setMethods(['flushAll'])
            ->getMock()
        ;
    }

    /**
     * @param array $methods
     *
     * @return CsrfTokenManager|MockObject
     */
    protected function getMockCsrfTokenManager($methods = ['isTokenValid'])
    {
        return $this->getMockBuilder(CsrfTokenManager::class)
            ->setMethods($methods)
            ->setConstructorArgs([null, new SessionTokenStorage(new Session(new MockArraySessionStorage()))])
            ->getMock()
        ;
    }

    /**
     * @return Client|MockObject
     */
    protected function getMockGuzzleClient()
    {
        return $this->getMockBuilder(Client::class)
            ->setMethods(['get'])
            ->getMock()
        ;
    }

    /**
     * @param array $methods
     *
     * @return FlashLogger|MockObject
     */
    protected function getMockFlashLogger($methods = ['danger', 'error', 'success'])
    {
        return $this->getMockBuilder(FlashLogger::class)
            ->setMethods($methods)
            ->getMock()
        ;
    }

    /**
     * @param array $methods Defaults to ['login']
     *
     * @return MockObject A mocked \Bolt\AccessControl\Login
     */
    protected function getMockLogin($methods = ['login'])
    {
        return $this->getMockBuilder(Login::class)
            ->setMethods($methods)
            ->setConstructorArgs([$this->getApp()])
            ->getMock()
        ;
    }

    /**
     * @param array $methods
     *
     * @return Manager|MockObject
     */
    protected function getMockLoggerManager($methods = ['clear', 'error', 'info', 'trim'])
    {
        $app = $this->getApp();
        $changeRepository = $this->getService('storage')->getRepository(Entity\LogChange::class);
        $systemRepository = $this->getService('storage')->getRepository(Entity\LogSystem::class);

        return $this->getMockBuilder(Manager::class)
            ->setMethods($methods)
            ->setConstructorArgs([$app, $changeRepository, $systemRepository])
            ->getMock()
        ;
    }

    /**
     * @param array $methods
     *
     * @return Logger|MockObject
     */
    protected function getMockMonolog($methods = ['alert', 'clear', 'debug', 'error', 'info'])
    {
        return $this->getMockBuilder(Logger::class)
            ->setMethods($methods)
            ->setConstructorArgs(['testlogger'])
            ->getMock()
        ;
    }

    /**
     * @param array $methods
     *
     * @return Permissions|MockObject
     */
    protected function getMockPermissions($methods = ['isAllowed', 'isAllowedToManipulate'])
    {
        return $this->getMockBuilder(Permissions::class)
            ->setMethods($methods)
            ->setConstructorArgs([$this->getApp()])
            ->getMock()
        ;
    }

    /**
     * @param array $methods
     *
     * @return MockObject|Swift_Mailer
     */
    protected function getMockSwiftMailer($methods = ['send'])
    {
        return $this->getMockBuilder(Swift_Mailer::class)
            ->setMethods($methods)
            ->disableOriginalConstructor()
            ->getMock()
        ;
    }

    /**
     * @param array $methods
     *
     * @return Storage|MockObject
     */
    protected function getMockStorage($methods = ['getContent', 'getContentType', 'getTaxonomyType'])
    {
        return $this->getMockBuilder(Storage::class)
            ->setMethods($methods)
            ->setConstructorArgs([$this->getApp()])
            ->getMock()
        ;
    }

    /**
     * @param array $methods
     *
     * @return Users|MockObject
     */
    protected function getMockUsers($methods = ['getUsers', 'isAllowed'])
    {
        return $this->getMockBuilder(Users::class)
            ->setMethods($methods)
            ->setConstructorArgs([$this->getApp()])
            ->getMock()
        ;
    }

    /**
     * @deprecated remove in v4 as PHPUnit 5 includes this
     *
     * @param mixed $originalClassName
     *
     * @return MockObject
     */
    protected function createMock($originalClassName)
    {
        return $this->getMockBuilder($originalClassName)
            ->disableOriginalConstructor()
            ->disableOriginalClone()
            ->disableArgumentCloning()
            ->getMock()
        ;
    }
}

<MSG> [Tests] Put addNewUser() into parent class
<DFF> @@ -158,4 +158,19 @@ abstract class BoltUnitTest extends \PHPUnit_Framework_TestCase
             'utils'  => $app->share(function () use ($app) { return new UtilsHandler($app); }),
         ));
     }
+
+    protected function addNewUser($app, $username, $displayname, $role)
+    {
+        $user = $app['users']->getEmptyUser();
+
+        unset($user['id']);
+        $user['username']    = $username;
+        $user['displayname'] = $displayname;
+        $user['email']       = $username.'@example.com';
+        $user['password']    = 'password';
+        $user['roles']       = array($role);
+
+        $app['users']->saveUser($user);
+        $app['users']->users = array();
+    }
 }

{'commit': "diff --git a/tests/phpunit/unit/BoltUnitTest.php b/tests/phpunit/unit/BoltUnitTest.php\nindex 40611fe0f..a3ae6e24f 100644\n--- a/tests/phpunit/unit/BoltUnitTest.php\n+++ b/tests/phpunit/unit/BoltUnitTest.php\n@@ -158,4 +158,19 @@ abstract class BoltUnitTest extends \\PHPUnit_Framework_TestCase\n             'utils'  => $app->share(function () use ($app) { return new UtilsHandler($app); }),\n         ));\n     }\n+\n+    protected function addNewUser($app, $username, $displayname, $role)\n+    {\n+        $user = $app['users']->getEmptyUser();\n+\n+        unset($user['id']);\n+        $user['username']    = $username;\n+        $user['displayname'] = $displayname;\n+        $user['email']       = $username.'@example.com';\n+        $user['password']    = 'password';\n+        $user['roles']       = array($role);\n+\n+        $app['users']->saveUser($user);\n+        $app['users']->users = array();\n+    }\n }\n", 'commit_subject': '[Tests] Put addNewUser() into parent class', 'repo_name': 'bolt/bolt', 'committer': {'name': 'Gawain Lynch', 'email': 'f745ec5336bcd096400627fc09f6ec7139408726@gmail.com', 'time_sec': '1429947121', 'tz_offset': '60', 'date': {'seconds': '1429947121'}}, 'commit_tree': 'ff2eb7517ea0f484249973d50b8e7a7cdca5d35f', 'commit_message': '[Tests] Put addNewUser() into parent class', 'language_name': 'JavaScript', 'license': 'mit', 'hunks': "@@ -158,4 +158,19 @@ abstract class BoltUnitTest extends \\PHPUnit_Framework_TestCase\n             'utils'  => $app->share(function () use ($app) { return new UtilsHandler($app); }),\n         ));\n     }\n+\n+    protected function addNewUser($app, $username, $displayname, $role)\n+    {\n+        $user = $app['users']->getEmptyUser();\n+\n+        unset($user['id']);\n+        $user['username']    = $username;\n+        $user['displayname'] = $displayname;\n+        $user['email']       = $username.'@example.com';\n+        $user['password']    = 'password';\n+        $user['roles']       = array($role);\n+\n+        $app['users']->saveUser($user);\n+        $app['users']->users = array();\n+    }\n }\n", 'addition_count': 15, 'deletion_count': 0, 'src_file': 'a/tests/phpunit/unit/BoltUnitTest.php', 'tgt_file': 'b/tests/phpunit/unit/BoltUnitTest.php', 'file_extension': '.php', 'before_file': "<?php\n\nnamespace Bolt\\Tests;\n\nuse Bolt;\nuse Bolt\\AccessControl\\AccessChecker;\nuse Bolt\\AccessControl\\Login;\nuse Bolt\\AccessControl\\Permissions;\nuse Bolt\\AccessControl\\Token;\nuse Bolt\\Configuration as Config;\nuse Bolt\\Legacy\\Storage;\nuse Bolt\\Logger\\FlashLogger;\nuse Bolt\\Logger\\Manager;\nuse Bolt\\Storage\\Entity;\nuse Bolt\\Tests\\Mocks\\ImageApiMock;\nuse Bolt\\Tests\\Mocks\\LoripsumMock;\nuse Bolt\\Users;\nuse Doctrine\\Common\\Cache\\VoidCache;\nuse GuzzleHttp\\Client;\nuse Monolog\\Logger;\nuse PHPUnit\\Framework\\TestCase;\nuse PHPUnit_Framework_MockObject_MockObject as MockObject;\nuse Silex\\Application;\nuse Swift_Mailer;\nuse Symfony\\Component\\HttpFoundation\\Session\\Session;\nuse Symfony\\Component\\HttpFoundation\\Session\\Storage\\MockArraySessionStorage;\nuse Symfony\\Component\\Security\\Csrf\\CsrfTokenManager;\nuse Symfony\\Component\\Security\\Csrf\\TokenStorage\\SessionTokenStorage;\n\n/**\n * Abstract Class that other unit tests can extend, provides generic methods for Bolt tests.\n *\n * @author Ross Riley <riley.ross@gmail.com>\n **/\nabstract class BoltUnitTest extends TestCase\n{\n    /** @var \\Silex\\Application|\\Bolt\\Application */\n    private $app;\n\n    protected function resetDb()\n    {\n        // Make sure we wipe the db file to start with a clean one\n        if (is_readable(PHPUNIT_WEBROOT . '/app/database/bolt.db')) {\n            unlink(PHPUNIT_WEBROOT . '/app/database/bolt.db');\n            copy(PHPUNIT_ROOT . '/resources/db/bolt.db', PHPUNIT_WEBROOT . '/app/database/bolt.db');\n        }\n    }\n\n    protected function resetConfig()\n    {\n        $configFiles = [\n            'config.yml',\n            'contenttypes.yml',\n            'menu.yml',\n            'permissions.yml',\n            'routing.yml',\n            'taxonomy.yml',\n        ];\n        foreach ($configFiles as $configFile) {\n            // Make sure we wipe the db file to start with a clean one\n            if (is_readable(PHPUNIT_WEBROOT . '/app/config/' . $configFile)) {\n                unlink(PHPUNIT_WEBROOT . '/app/config/' . $configFile);\n            }\n        }\n        if (is_readable(PHPUNIT_WEBROOT . '/app/cache/config-cache.json')) {\n            unlink(PHPUNIT_WEBROOT . '/app/cache/config-cache.json');\n        }\n    }\n\n    /**\n     * @param bool $boot\n     *\n     * @return \\Silex\\Application\n     */\n    protected function getApp($boot = true)\n    {\n        if (!$this->app) {\n            $this->app = $this->makeApp();\n            $this->app->initialize();\n\n            $verifier = new Config\\Validation\\Validator(\n                $this->app['config'],\n                $this->app['path_resolver'],\n                $this->app['logger.flash']\n            );\n            $verifier->checks();\n\n            if ($boot) {\n                $this->app->boot();\n                $this->app->flush();\n            }\n        }\n\n        return $this->app;\n    }\n\n    /**\n     * @return \\Silex\\Application\n     */\n    protected function makeApp()\n    {\n        $app = new Bolt\\Application();\n        $app['path_resolver.root'] = PHPUNIT_WEBROOT;\n        $app['path_resolver.paths'] = ['web' => '.'];\n        $app['debug'] = false;\n\n        $app['config']->set(\n            'general/database',\n            [\n                'driver'       => 'pdo_sqlite',\n                'prefix'       => 'bolt_',\n                'user'         => 'test',\n                'path'         => PHPUNIT_WEBROOT . '/app/database/bolt.db',\n                'wrapperClass' => '\\Bolt\\Storage\\Database\\Connection',\n            ]\n        );\n\n        return $app;\n    }\n\n    protected function rmdir($dir)\n    {\n        if (!is_dir($dir)) {\n            return;\n        }\n        $iterator = new \\RecursiveIteratorIterator(\n            new \\RecursiveDirectoryIterator($dir, \\FilesystemIterator::SKIP_DOTS),\n            \\RecursiveIteratorIterator::CHILD_FIRST\n        );\n        foreach ($iterator as $file) {\n            if ($file->isDir()) {\n                rmdir($file->getPathname());\n            } else {\n                unlink($file->getPathname());\n            }\n        }\n        rmdir($dir);\n    }\n\n    protected function addDefaultUser(Application $app)\n    {\n        // Check if default user exists before adding\n        $existingUser = $app['users']->getUser('admin');\n        if ($existingUser !== false) {\n            return $existingUser;\n        }\n\n        $user = [\n            'username'    => 'admin',\n            'password'    => 'password',\n            'email'       => 'admin@example.com',\n            'displayname' => 'Admin',\n            'roles'       => ['admin'],\n            'enabled'     => true,\n        ];\n\n        $app['users']->saveUser(array_merge($app['users']->getEmptyUser(), $user));\n            'utils'  => $app->share(function () use ($app) { return new UtilsHandler($app); }),\n        ));\n    }\n}\n    }\n\n    protected function allowLogin($app)\n    {\n        $this->addDefaultUser($app);\n        $users = $this->getMockUsers(['isEnabled']);\n        $users->expects($this->any())\n            ->method('isEnabled')\n            ->will($this->returnValue(true));\n        $this->setService('users', $users);\n\n        $permissions = $this->getMockPermissions(['isAllowed']);\n        $permissions->expects($this->any())\n            ->method('isAllowed')\n            ->will($this->returnValue(true));\n        $this->setService('permissions', $permissions);\n\n        $auth = $this->getMockAccessChecker($app);\n        $auth->expects($this->any())\n            ->method('isValidSession')\n            ->will($this->returnValue(true));\n\n        $this->setService('access_control', $auth);\n    }\n\n    protected function removeCSRF($app)\n    {\n        // Symfony forms need a CSRF token so we have to mock this too\n        $csrf = $this->getMockCsrfTokenManager(['isTokenValid', 'getToken']);\n        $csrf->expects($this->any())\n            ->method('isTokenValid')\n            ->will($this->returnValue(true));\n\n        $csrf->expects($this->any())\n            ->method('getToken')\n            ->will($this->returnValue('xyz'));\n\n        $this->setService('form.csrf_provider', $csrf);\n    }\n\n    /**\n     * @param array $contentTypes\n     * @param array $categories\n     * @param int   $count\n     */\n    protected function addSomeContent($contentTypes = null, $categories = null, $count = null)\n    {\n        $contentTypes = $contentTypes ?: ['showcases', 'pages', 'homepage'];\n        $categories = $categories ?: ['news'];\n        $count = $count ?: 5;\n\n        $app = $this->getApp();\n        $this->addDefaultUser($app);\n        $app['config']->set('taxonomy/categories/options', $categories);\n        $this->setService('prefill', new LoripsumMock());\n        $this->setService('prefill.image', new ImageApiMock());\n\n        $builder = $app['prefill.builder'];\n        $builder->build($contentTypes, $count);\n    }\n\n    /**\n     * @param string $key\n     * @param mixed  $value\n     */\n    protected function setService($key, $value)\n    {\n        // In Pimple v3+ you can't re-set a container value,\n        // this just keeps us working forward with tests.\n        $this->getApp()->offsetUnset($key);\n        $this->getApp()->offsetSet($key, $value);\n    }\n\n    protected function getService($key)\n    {\n        return $this->getApp()->offsetGet($key);\n    }\n\n    protected function setSessionUser(Entity\\Users $userEntity)\n    {\n        $tokenEntity = new Entity\\Authtoken();\n        $tokenEntity->setToken('testtoken');\n        $authToken = new Token\\Token($userEntity, $tokenEntity);\n\n        $this->getService('session')->set('authentication', $authToken);\n    }\n\n    /*\n     * MOCKS\n     */\n\n    /**\n     * @param \\Silex\\Application $app\n     * @param array              $methods Defaults to ['isValidSession']\n     *\n     * @return \\Bolt\\AccessControl\\AccessChecker|MockObject\n     */\n    protected function getMockAccessChecker($app, $methods = ['isValidSession'])\n    {\n        $parameters = [\n            $app['storage.lazy'],\n            $app['request_stack'],\n            $app['session'],\n            $app['dispatcher'],\n            $app['logger.flash'],\n            $app['logger.system'],\n            $app['permissions'],\n            $app['randomgenerator'],\n            $app['access_control.cookie.options'],\n        ];\n        $accessCheckerMock = $this->getMockBuilder(AccessChecker::class)\n            ->setMethods($methods)\n            ->setConstructorArgs($parameters)\n            ->getMock()\n        ;\n\n        return $accessCheckerMock;\n    }\n\n    /**\n     * @return VoidCache|MockObject\n     */\n    protected function getMockCache()\n    {\n        return $this->getMockBuilder(VoidCache::class)\n            ->setMethods(['flushAll'])\n            ->getMock()\n        ;\n    }\n\n    /**\n     * @param array $methods\n     *\n     * @return CsrfTokenManager|MockObject\n     */\n    protected function getMockCsrfTokenManager($methods = ['isTokenValid'])\n    {\n        return $this->getMockBuilder(CsrfTokenManager::class)\n            ->setMethods($methods)\n            ->setConstructorArgs([null, new SessionTokenStorage(new Session(new MockArraySessionStorage()))])\n            ->getMock()\n        ;\n    }\n\n    /**\n     * @return Client|MockObject\n     */\n    protected function getMockGuzzleClient()\n    {\n        return $this->getMockBuilder(Client::class)\n            ->setMethods(['get'])\n            ->getMock()\n        ;\n    }\n\n    /**\n     * @param array $methods\n     *\n     * @return FlashLogger|MockObject\n     */\n    protected function getMockFlashLogger($methods = ['danger', 'error', 'success'])\n    {\n        return $this->getMockBuilder(FlashLogger::class)\n            ->setMethods($methods)\n            ->getMock()\n        ;\n    }\n\n    /**\n     * @param array $methods Defaults to ['login']\n     *\n     * @return MockObject A mocked \\Bolt\\AccessControl\\Login\n     */\n    protected function getMockLogin($methods = ['login'])\n    {\n        return $this->getMockBuilder(Login::class)\n            ->setMethods($methods)\n            ->setConstructorArgs([$this->getApp()])\n            ->getMock()\n        ;\n    }\n\n    /**\n     * @param array $methods\n     *\n     * @return Manager|MockObject\n     */\n    protected function getMockLoggerManager($methods = ['clear', 'error', 'info', 'trim'])\n    {\n        $app = $this->getApp();\n        $changeRepository = $this->getService('storage')->getRepository(Entity\\LogChange::class);\n        $systemRepository = $this->getService('storage')->getRepository(Entity\\LogSystem::class);\n\n        return $this->getMockBuilder(Manager::class)\n            ->setMethods($methods)\n            ->setConstructorArgs([$app, $changeRepository, $systemRepository])\n            ->getMock()\n        ;\n    }\n\n    /**\n     * @param array $methods\n     *\n     * @return Logger|MockObject\n     */\n    protected function getMockMonolog($methods = ['alert', 'clear', 'debug', 'error', 'info'])\n    {\n        return $this->getMockBuilder(Logger::class)\n            ->setMethods($methods)\n            ->setConstructorArgs(['testlogger'])\n            ->getMock()\n        ;\n    }\n\n    /**\n     * @param array $methods\n     *\n     * @return Permissions|MockObject\n     */\n    protected function getMockPermissions($methods = ['isAllowed', 'isAllowedToManipulate'])\n    {\n        return $this->getMockBuilder(Permissions::class)\n            ->setMethods($methods)\n            ->setConstructorArgs([$this->getApp()])\n            ->getMock()\n        ;\n    }\n\n    /**\n     * @param array $methods\n     *\n     * @return MockObject|Swift_Mailer\n     */\n    protected function getMockSwiftMailer($methods = ['send'])\n    {\n        return $this->getMockBuilder(Swift_Mailer::class)\n            ->setMethods($methods)\n            ->disableOriginalConstructor()\n            ->getMock()\n        ;\n    }\n\n    /**\n     * @param array $methods\n     *\n     * @return Storage|MockObject\n     */\n    protected function getMockStorage($methods = ['getContent', 'getContentType', 'getTaxonomyType'])\n    {\n        return $this->getMockBuilder(Storage::class)\n            ->setMethods($methods)\n            ->setConstructorArgs([$this->getApp()])\n            ->getMock()\n        ;\n    }\n\n    /**\n     * @param array $methods\n     *\n     * @return Users|MockObject\n     */\n    protected function getMockUsers($methods = ['getUsers', 'isAllowed'])\n    {\n        return $this->getMockBuilder(Users::class)\n            ->setMethods($methods)\n            ->setConstructorArgs([$this->getApp()])\n            ->getMock()\n        ;\n    }\n\n    /**\n     * @deprecated remove in v4 as PHPUnit 5 includes this\n     *\n     * @param mixed $originalClassName\n     *\n     * @return MockObject\n     */\n    protected function createMock($originalClassName)\n    {\n        return $this->getMockBuilder($originalClassName)\n            ->disableOriginalConstructor()\n            ->disableOriginalClone()\n            ->disableArgumentCloning()\n            ->getMock()\n        ;\n    }\n}\n", 'message': '[Tests] Put addNewUser() into parent class', 'author_name': 'Gawain Lynch', 'lang': 'php'}