summaryrefslogtreecommitdiff
path: root/tests/TestCase.php
diff options
context:
space:
mode:
authorGreg Roach <fisharebest@webtrees.net>2019-09-27 16:53:23 +0100
committerGreg Roach <fisharebest@webtrees.net>2019-09-29 23:36:06 +0100
commit57ab22314b2599feb432b1a1ed71643cfc2f0452 (patch)
tree2d34d10af028b68cd37da4ed0e5fda221b59474a /tests/TestCase.php
parentcf12f214bce265bdbd8467b72f2c1bcf7aae1c91 (diff)
downloadwebtrees-57ab22314b2599feb432b1a1ed71643cfc2f0452.tar.gz
webtrees-57ab22314b2599feb432b1a1ed71643cfc2f0452.tar.bz2
webtrees-57ab22314b2599feb432b1a1ed71643cfc2f0452.zip
Add tree to request; preparing for router
Diffstat (limited to 'tests/TestCase.php')
-rw-r--r--tests/TestCase.php97
1 files changed, 47 insertions, 50 deletions
diff --git a/tests/TestCase.php b/tests/TestCase.php
index c4cebb9458..b47ed389b4 100644
--- a/tests/TestCase.php
+++ b/tests/TestCase.php
@@ -32,6 +32,7 @@ use Illuminate\Cache\Repository;
use Illuminate\Database\Capsule\Manager as DB;
use Illuminate\Database\Query\Builder;
use League\Flysystem\Filesystem;
+use League\Flysystem\FilesystemInterface;
use League\Flysystem\Memory\MemoryAdapter;
use Nyholm\Psr7\Factory\Psr17Factory;
use Psr\Http\Message\ResponseFactoryInterface;
@@ -47,6 +48,7 @@ use function define;
use function defined;
use function filesize;
use function http_build_query;
+use function microtime;
use const UPLOAD_ERR_OK;
/**
@@ -54,11 +56,10 @@ use const UPLOAD_ERR_OK;
*/
class TestCase extends \PHPUnit\Framework\TestCase implements StatusCodeInterface
{
- /** @var bool */
- protected static $uses_database = false;
-
/** @var object */
public static $mock_functions;
+ /** @var bool */
+ protected static $uses_database = false;
/**
* Things to run once, before all the tests.
@@ -77,16 +78,11 @@ class TestCase extends \PHPUnit\Framework\TestCase implements StatusCodeInterfac
// Use an array cache for database calls, etc.
app()->instance('cache.array', new Repository(new ArrayStore()));
- app()->bind(Tree::class, static function () {
- return null;
- });
-
app()->instance(UserService::class, new UserService());
- app()->instance(UserInterface::class, new GuestUser());
- app()->instance(Filesystem::class, new Filesystem(new MemoryAdapter()));
-
- app()->bind(ModuleThemeInterface::class, WebtreesTheme::class);
+ app()->instance(FilesystemInterface::class, new Filesystem(new MemoryAdapter()));
app()->bind(LocaleInterface::class, LocaleEnUs::class);
+ app()->bind(ModuleThemeInterface::class, WebtreesTheme::class);
+ app()->bind(UserInterface::class, GuestUser::class);
defined('WT_DATA_DIR') || define('WT_DATA_DIR', Webtrees::ROOT_DIR . 'data/');
defined('WT_LOCALE') || define('WT_LOCALE', I18N::init('en-US', null, true));
@@ -126,6 +122,37 @@ class TestCase extends \PHPUnit\Framework\TestCase implements StatusCodeInterfac
}
/**
+ * Create a request and bind it into the container.
+ *
+ * @param string $method
+ * @param string[] $query
+ * @param string[] $params
+ * @param UploadedFileInterface[] $files
+ *
+ * @return ServerRequestInterface
+ */
+ protected static function createRequest(string $method = 'GET', array $query = [], array $params = [], array $files = []): ServerRequestInterface
+ {
+ /** @var ServerRequestFactoryInterface */
+ $server_request_factory = app(ServerRequestFactoryInterface::class);
+
+ $uri = 'https://webtrees.test/index.php?' . http_build_query($query);
+
+ /** @var ServerRequestInterface $request */
+ $request = $server_request_factory
+ ->createServerRequest($method, $uri)
+ ->withQueryParams($query)
+ ->withParsedBody($params)
+ ->withUploadedFiles($files)
+ ->withAttribute('base_url', 'https://webtrees.test')
+ ->withAttribute('client_ip', '127.0.0.1');
+
+ app()->instance(ServerRequestInterface::class, $request);
+
+ return $request;
+ }
+
+ /**
* Things to run once, AFTER all the tests.
*/
public static function tearDownAfterClass()
@@ -184,10 +211,13 @@ class TestCase extends \PHPUnit\Framework\TestCase implements StatusCodeInterfac
$tree->importGedcomFile($stream, $gedcom_file);
View::share('tree', $tree);
- $gedcom_file_controller = new GedcomFileController();
+
+ $timeout_service = new TimeoutService(microtime(true));
+ $controller = new GedcomFileController($timeout_service);
+ $request = self::createRequest()->withAttribute('tree', $tree);
do {
- $gedcom_file_controller->import(new TimeoutService(microtime(true)), $tree);
+ $controller->import($request);
$imported = $tree->getPreference('imported');
} while (!$imported);
@@ -196,36 +226,6 @@ class TestCase extends \PHPUnit\Framework\TestCase implements StatusCodeInterfac
}
/**
- * Create a request and bind it into the container.
- *
- * @param string $method
- * @param string[] $query
- * @param string[] $params
- * @param UploadedFileInterface[] $files
- *
- * @return ServerRequestInterface
- */
- protected static function createRequest(string $method = 'GET', array $query = [], array $params = [], array $files = []): ServerRequestInterface
- {
- /** @var ServerRequestFactoryInterface */
- $server_request_factory = app(ServerRequestFactoryInterface::class);
-
- $uri = 'http://localhost/index.php?' . http_build_query($query);
-
- /** @var ServerRequestInterface $request */
- $request = $server_request_factory
- ->createServerRequest($method, $uri)
- ->withQueryParams($query)
- ->withParsedBody($params)
- ->withUploadedFiles($files)
- ->withAttribute('client_ip', '127.0.0.1');
-
- app()->instance(ServerRequestInterface::class, $request);
-
- return $request;
- }
-
- /**
* Create an uploaded file for a request.
*
* @param string $filename
@@ -237,16 +237,13 @@ class TestCase extends \PHPUnit\Framework\TestCase implements StatusCodeInterfac
{
/** @var StreamFactoryInterface */
$stream_factory = app(StreamFactoryInterface::class);
-
+
/** @var UploadedFileFactoryInterface */
$uploaded_file_factory = app(UploadedFileFactoryInterface::class);
- $stream = $stream_factory->createStreamFromFile($filename);
-
- $size = filesize($filename);
-
- $status = UPLOAD_ERR_OK;
-
+ $stream = $stream_factory->createStreamFromFile($filename);
+ $size = filesize($filename);
+ $status = UPLOAD_ERR_OK;
$client_name = basename($filename);
return $uploaded_file_factory->createUploadedFile($stream, $size, $status, $client_name, $mime_type);