Tests: Replaced duplicates and formatting/cleanup
This commit is contained in:
parent
867d720f15
commit
2cce967eb0
|
@ -23,21 +23,9 @@ class ConfigServiceProviderTest extends ServiceProviderTest
|
||||||
*/
|
*/
|
||||||
public function testRegister()
|
public function testRegister()
|
||||||
{
|
{
|
||||||
|
/** @var Application|MockObject $app */
|
||||||
/** @var Config|MockObject $config */
|
/** @var Config|MockObject $config */
|
||||||
$config = $this->getMockBuilder(Config::class)
|
list($app, $config) = $this->getConfiguredApp(__DIR__ . '/../../../config');
|
||||||
->getMock();
|
|
||||||
|
|
||||||
$app = $this->getApp(['make', 'instance', 'get']);
|
|
||||||
Application::setInstance($app);
|
|
||||||
|
|
||||||
$this->setExpects($app, 'make', [Config::class], $config);
|
|
||||||
$this->setExpects($app, 'get', ['path.config'], __DIR__ . '/../../../config', $this->atLeastOnce());
|
|
||||||
$app->expects($this->exactly(2))
|
|
||||||
->method('instance')
|
|
||||||
->withConsecutive(
|
|
||||||
[Config::class, $config],
|
|
||||||
['config', $config]
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->setExpects($config, 'set', null, null, $this->exactly(2));
|
$this->setExpects($config, 'set', null, null, $this->exactly(2));
|
||||||
$config->expects($this->exactly(3))
|
$config->expects($this->exactly(3))
|
||||||
|
@ -64,21 +52,9 @@ class ConfigServiceProviderTest extends ServiceProviderTest
|
||||||
*/
|
*/
|
||||||
public function testRegisterException()
|
public function testRegisterException()
|
||||||
{
|
{
|
||||||
|
/** @var Application|MockObject $app */
|
||||||
/** @var Config|MockObject $config */
|
/** @var Config|MockObject $config */
|
||||||
$config = $this->getMockBuilder(Config::class)
|
list($app, $config) = $this->getConfiguredApp(__DIR__ . '/not_existing');
|
||||||
->getMock();
|
|
||||||
|
|
||||||
$app = $this->getApp(['make', 'instance', 'get']);
|
|
||||||
Application::setInstance($app);
|
|
||||||
|
|
||||||
$this->setExpects($app, 'make', [Config::class], $config);
|
|
||||||
$app->expects($this->exactly(2))
|
|
||||||
->method('instance')
|
|
||||||
->withConsecutive(
|
|
||||||
[Config::class, $config],
|
|
||||||
['config', $config]
|
|
||||||
);
|
|
||||||
$this->setExpects($app, 'get', ['path.config'], __DIR__ . '/not_existing', $this->atLeastOnce());
|
|
||||||
|
|
||||||
$this->setExpects($config, 'set', null, null, $this->never());
|
$this->setExpects($config, 'set', null, null, $this->never());
|
||||||
$this->setExpects($config, 'get', [null], []);
|
$this->setExpects($config, 'get', [null], []);
|
||||||
|
@ -151,4 +127,29 @@ class ConfigServiceProviderTest extends ServiceProviderTest
|
||||||
$config->get(null)
|
$config->get(null)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $configPath
|
||||||
|
* @return Application[]|Config[]
|
||||||
|
*/
|
||||||
|
protected function getConfiguredApp(string $configPath)
|
||||||
|
{
|
||||||
|
/** @var Config|MockObject $config */
|
||||||
|
$config = $this->getMockBuilder(Config::class)
|
||||||
|
->getMock();
|
||||||
|
|
||||||
|
$app = $this->getApp(['make', 'instance', 'get']);
|
||||||
|
Application::setInstance($app);
|
||||||
|
|
||||||
|
$this->setExpects($app, 'make', [Config::class], $config);
|
||||||
|
$this->setExpects($app, 'get', ['path.config'], $configPath, $this->atLeastOnce());
|
||||||
|
$app->expects($this->exactly(2))
|
||||||
|
->method('instance')
|
||||||
|
->withConsecutive(
|
||||||
|
[Config::class, $config],
|
||||||
|
['config', $config]
|
||||||
|
);
|
||||||
|
|
||||||
|
return [$app, $config];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,7 +61,7 @@ class PasswordResetControllerTest extends TestCase
|
||||||
|
|
||||||
$controller->postReset($request);
|
$controller->postReset($request);
|
||||||
|
|
||||||
$this->assertNotEmpty(PasswordReset::find($user->id)->first());
|
$this->assertNotEmpty((new PasswordReset())->find($user->id)->first());
|
||||||
$this->assertTrue($log->hasInfoThatContains($user->name));
|
$this->assertTrue($log->hasInfoThatContains($user->name));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,7 +152,7 @@ class PasswordResetControllerTest extends TestCase
|
||||||
$response = $controller->postResetPassword($request);
|
$response = $controller->postResetPassword($request);
|
||||||
$this->assertEquals(200, $response->getStatusCode());
|
$this->assertEquals(200, $response->getStatusCode());
|
||||||
|
|
||||||
$this->assertEmpty(PasswordReset::find($user->id));
|
$this->assertEmpty((new PasswordReset)->find($user->id));
|
||||||
$this->assertNotNull(auth()->authenticate($user->name, $password));
|
$this->assertNotNull(auth()->authenticate($user->name, $password));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ namespace Engelsystem\Test\Unit\Helpers\Stub;
|
||||||
|
|
||||||
use Engelsystem\Models\User\User;
|
use Engelsystem\Models\User\User;
|
||||||
use Illuminate\Database\Eloquent\Collection;
|
use Illuminate\Database\Eloquent\Collection;
|
||||||
|
use Illuminate\Database\Query\Builder as QueryBuilder;
|
||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
|
|
||||||
class UserModelImplementation extends User
|
class UserModelImplementation extends User
|
||||||
|
@ -22,7 +23,7 @@ class UserModelImplementation extends User
|
||||||
* @param array $columns
|
* @param array $columns
|
||||||
* @return User|null
|
* @return User|null
|
||||||
*/
|
*/
|
||||||
public static function find($id, $columns = ['*'])
|
public function find($id, $columns = ['*'])
|
||||||
{
|
{
|
||||||
if ($id != static::$id) {
|
if ($id != static::$id) {
|
||||||
throw new InvalidArgumentException('Wrong user ID searched');
|
throw new InvalidArgumentException('Wrong user ID searched');
|
||||||
|
@ -33,7 +34,7 @@ class UserModelImplementation extends User
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $apiKey
|
* @param string $apiKey
|
||||||
* @return User[]|Collection|\Illuminate\Database\Query\Builder
|
* @return User[]|Collection|QueryBuilder
|
||||||
*/
|
*/
|
||||||
public static function whereApiKey($apiKey)
|
public static function whereApiKey($apiKey)
|
||||||
{
|
{
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace Engelsystem\Test\Unit\Middleware\Stub;
|
namespace Engelsystem\Test\Unit\Middleware\Stub;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
use Psr\Http\Message\ResponseInterface;
|
use Psr\Http\Message\ResponseInterface;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
use Psr\Http\Server\RequestHandlerInterface;
|
use Psr\Http\Server\RequestHandlerInterface;
|
||||||
|
@ -21,7 +22,7 @@ class ReturnResponseMiddlewareHandler implements RequestHandlerInterface
|
||||||
*
|
*
|
||||||
* @param ServerRequestInterface $request
|
* @param ServerRequestInterface $request
|
||||||
* @return ResponseInterface
|
* @return ResponseInterface
|
||||||
* @throws \Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function handle(ServerRequestInterface $request): ResponseInterface
|
public function handle(ServerRequestInterface $request): ResponseInterface
|
||||||
{
|
{
|
||||||
|
|
|
@ -65,7 +65,7 @@ class EventConfigTest extends TestCase
|
||||||
->save();
|
->save();
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
'2001-02-03 00:00',
|
'2001-02-03 00:00',
|
||||||
EventConfig::find('buildup_start')
|
(new EventConfig())->find('buildup_start')
|
||||||
->value
|
->value
|
||||||
->format('Y-m-d H:i')
|
->format('Y-m-d H:i')
|
||||||
);
|
);
|
||||||
|
|
|
@ -11,6 +11,7 @@ use Engelsystem\Models\User\State;
|
||||||
use Engelsystem\Models\User\User;
|
use Engelsystem\Models\User\User;
|
||||||
use Engelsystem\Test\Unit\HasDatabase;
|
use Engelsystem\Test\Unit\HasDatabase;
|
||||||
use Engelsystem\Test\Unit\TestCase;
|
use Engelsystem\Test\Unit\TestCase;
|
||||||
|
use Exception;
|
||||||
|
|
||||||
class UserTest extends TestCase
|
class UserTest extends TestCase
|
||||||
{
|
{
|
||||||
|
@ -75,6 +76,7 @@ class UserTest extends TestCase
|
||||||
* @param string $class
|
* @param string $class
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param array $data
|
* @param array $data
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function testHasOneRelations($class, $name, $data)
|
public function testHasOneRelations($class, $name, $data)
|
||||||
{
|
{
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
namespace Engelsystem\Test\Unit\Renderer\Twig\Extensions;
|
namespace Engelsystem\Test\Unit\Renderer\Twig\Extensions;
|
||||||
|
|
||||||
use DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts;
|
use DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts;
|
||||||
|
use Exception;
|
||||||
use PHPUnit\Framework\MockObject\MockObject;
|
use PHPUnit\Framework\MockObject\MockObject;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use Twig_Function as TwigFunction;
|
use Twig_Function as TwigFunction;
|
||||||
|
@ -40,6 +41,7 @@ abstract class ExtensionTest extends TestCase
|
||||||
* @param callable $callback
|
* @param callable $callback
|
||||||
* @param TwigFunction[] $functions
|
* @param TwigFunction[] $functions
|
||||||
* @param array $options
|
* @param array $options
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
protected function assertExtensionExists($name, $callback, $functions, $options = [])
|
protected function assertExtensionExists($name, $callback, $functions, $options = [])
|
||||||
{
|
{
|
||||||
|
@ -69,6 +71,7 @@ abstract class ExtensionTest extends TestCase
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
* @param mixed[] $globals
|
* @param mixed[] $globals
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
protected function assertGlobalsExists($name, $value, $globals)
|
protected function assertGlobalsExists($name, $value, $globals)
|
||||||
{
|
{
|
||||||
|
@ -86,6 +89,7 @@ abstract class ExtensionTest extends TestCase
|
||||||
*
|
*
|
||||||
* @param $tokenParser
|
* @param $tokenParser
|
||||||
* @param $tokenParsers
|
* @param $tokenParsers
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
protected function assertTokenParserExists($tokenParser, $tokenParsers)
|
protected function assertTokenParserExists($tokenParser, $tokenParsers)
|
||||||
{
|
{
|
||||||
|
|
|
@ -9,6 +9,7 @@ use Engelsystem\Renderer\TwigServiceProvider;
|
||||||
use Engelsystem\Test\Unit\ServiceProviderTest;
|
use Engelsystem\Test\Unit\ServiceProviderTest;
|
||||||
use PHPUnit\Framework\MockObject\MockObject;
|
use PHPUnit\Framework\MockObject\MockObject;
|
||||||
use ReflectionClass as Reflection;
|
use ReflectionClass as Reflection;
|
||||||
|
use ReflectionException;
|
||||||
use stdClass;
|
use stdClass;
|
||||||
use Twig_Environment as Twig;
|
use Twig_Environment as Twig;
|
||||||
use Twig_Extension_Core as TwigCore;
|
use Twig_Extension_Core as TwigCore;
|
||||||
|
@ -163,7 +164,7 @@ class TwigServiceProviderTest extends ServiceProviderTest
|
||||||
/**
|
/**
|
||||||
* @param TwigServiceProvider $serviceProvider
|
* @param TwigServiceProvider $serviceProvider
|
||||||
* @param array $extensions
|
* @param array $extensions
|
||||||
* @throws \ReflectionException
|
* @throws ReflectionException
|
||||||
*/
|
*/
|
||||||
protected function setExtensionsTo($serviceProvider, $extensions)
|
protected function setExtensionsTo($serviceProvider, $extensions)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue