Skip to content

Commit

Permalink
tests: improved descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Feb 2, 2025
1 parent cf9dac5 commit 486ec41
Show file tree
Hide file tree
Showing 28 changed files with 121 additions and 122 deletions.
17 changes: 7 additions & 10 deletions tests/Application/Application.run.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@ $httpResponse = Mockery::mock(Nette\Http\IResponse::class);
$httpResponse->shouldIgnoreMissing();


// no route without error presenter
Assert::exception(function () use ($httpRequest, $httpResponse) {
testException('No route handling without error presenter', function () use ($httpRequest, $httpResponse) {
$presenterFactory = Mockery::mock(IPresenterFactory::class);
$router = Mockery::mock(Router::class);
$router->shouldReceive('match')->andReturn(null);
Expand All @@ -107,7 +106,7 @@ Assert::exception(function () use ($httpRequest, $httpResponse) {
}, BadRequestException::class, 'No route for HTTP request.');


test('no route with error presenter', function () use ($httpRequest, $httpResponse) {
test('Error presenter handling for route mismatch', function () use ($httpRequest, $httpResponse) {
$errorPresenter = new ErrorPresenter;

$presenterFactory = Mockery::mock(IPresenterFactory::class);
Expand All @@ -133,7 +132,7 @@ test('no route with error presenter', function () use ($httpRequest, $httpRespon
});


test('route to error presenter', function () use ($httpRequest, $httpResponse) {
test('Error presenter invoked directly via router', function () use ($httpRequest, $httpResponse) {
$errorPresenter = new ErrorPresenter;

$presenterFactory = Mockery::mock(IPresenterFactory::class);
Expand Down Expand Up @@ -161,8 +160,7 @@ test('route to error presenter', function () use ($httpRequest, $httpResponse) {
});


// missing presenter without error presenter
Assert::exception(function () use ($httpRequest, $httpResponse) {
testException('Missing presenter exception without error presenter', function () use ($httpRequest, $httpResponse) {
$presenterFactory = Mockery::mock(IPresenterFactory::class);
$presenterFactory->shouldReceive('createPresenter')->with('Missing')->andThrow(Nette\Application\InvalidPresenterException::class);

Expand All @@ -174,7 +172,7 @@ Assert::exception(function () use ($httpRequest, $httpResponse) {
}, BadRequestException::class);


test('missing presenter with error presenter', function () use ($httpRequest, $httpResponse) {
test('Missing presenter fallback to error presenter', function () use ($httpRequest, $httpResponse) {
$errorPresenter = new ErrorPresenter;

$presenterFactory = Mockery::mock(IPresenterFactory::class);
Expand Down Expand Up @@ -203,8 +201,7 @@ test('missing presenter with error presenter', function () use ($httpRequest, $h
});


// presenter error without error presenter
Assert::exception(function () use ($httpRequest, $httpResponse) {
testException('Presenter exception propagation without error handling', function () use ($httpRequest, $httpResponse) {
$presenterFactory = Mockery::mock(IPresenterFactory::class);
$presenterFactory->shouldReceive('createPresenter')->with('Bad')->andReturn(new BadPresenter);

Expand All @@ -216,7 +213,7 @@ Assert::exception(function () use ($httpRequest, $httpResponse) {
}, BadException::class);


test('presenter error with error presenter', function () use ($httpRequest, $httpResponse) {
test('Presenter exception propagation to error presenter', function () use ($httpRequest, $httpResponse) {
$badPresenter = new BadPresenter;
$errorPresenter = new ErrorPresenter;

Expand Down
4 changes: 2 additions & 2 deletions tests/Application/MicroPresenter.invoke.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use Tester\Assert;
require __DIR__ . '/../bootstrap.php';


test('', function () {
test('Callback invocation with parameters', function () {
$presenter = $p = new NetteModule\MicroPresenter;

$presenter->run(new Request('Nette:Micro', 'GET', [
Expand All @@ -30,7 +30,7 @@ test('', function () {
});


test('', function () {
test('Dependency injection in callback', function () {
$container = Mockery::mock(Nette\DI\Container::class)
->shouldReceive('getByType')->with('stdClass', false)->once()->andReturn(new stdClass)
->mock();
Expand Down
14 changes: 7 additions & 7 deletions tests/Application/MicroPresenter.response.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function createContainer()
}


test('', function () {
test('TextResponse with direct output', function () {
$presenter = new NetteModule\MicroPresenter(createContainer());
$response = $presenter->run(new Request('Nette:Micro', 'GET', [
'callback' => fn() => 'test',
Expand All @@ -48,7 +48,7 @@ test('', function () {
});


test('', function () {
test('Parameter passing to callback', function () {
$presenter = new NetteModule\MicroPresenter(createContainer());
$response = $presenter->run(new Request('Nette:Micro', 'GET', [
'callback' => fn($param) => $param,
Expand All @@ -60,7 +60,7 @@ test('', function () {
});


test('', function () {
test('Latte template evaluation', function () {
$presenter = new NetteModule\MicroPresenter(createContainer());
$response = $presenter->run(new Request('Nette:Micro', 'GET', [
'callback' => fn() => '{=date(Y)}',
Expand All @@ -71,7 +71,7 @@ test('', function () {
});


test('', function () {
test('Template file with parameters', function () {
$presenter = new NetteModule\MicroPresenter(createContainer());
$response = $presenter->run(new Request('Nette:Micro', 'GET', [
'callback' => fn() => [new SplFileInfo(Tester\FileMock::create('{$param}')), []],
Expand All @@ -83,7 +83,7 @@ test('', function () {
});


test('', function () {
test('Manual template creation', function () {
$presenter = new NetteModule\MicroPresenter;

$response = $presenter->run(new Request('Nette:Micro', 'GET', [
Expand All @@ -101,7 +101,7 @@ test('', function () {
});


test('', function () {
test('Template file loader with parameters', function () {
$presenter = new NetteModule\MicroPresenter;

$response = $presenter->run(new Request('Nette:Micro', 'GET', [
Expand All @@ -120,7 +120,7 @@ test('', function () {
});


test('', function () {
test('Missing template file handling', function () {
$filename = 'notfound.latte';
Assert::exception(function () use ($filename) {
$presenter = new NetteModule\MicroPresenter;
Expand Down
15 changes: 8 additions & 7 deletions tests/Application/PresenterFactory.formatPresenterClass.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use Tester\Assert;
require __DIR__ . '/../bootstrap.php';


test('defined module', function () {
test('Complex mapping with multiple wildcards', function () {
$factory = new PresenterFactory;

$factory->setMapping([
Expand All @@ -36,7 +36,7 @@ test('defined module', function () {
});


test('auto module', function () {
test('Simple wildcard mapping', function () {
$factory = new PresenterFactory;

$factory->setMapping([
Expand All @@ -53,7 +53,7 @@ test('auto module', function () {
});


test('location ** & defined module', function () {
test('Multi-segment wildcard expansion', function () {
$factory = new PresenterFactory;

$factory->setMapping([
Expand All @@ -76,7 +76,7 @@ test('location ** & defined module', function () {
});


test('location ** & auto module', function () {
test('Global wildcard mapping strategy', function () {
$factory = new PresenterFactory;

$factory->setMapping([
Expand All @@ -94,7 +94,7 @@ test('location ** & auto module', function () {
});


test('', function () {
test('Array-based hierarchical mapping', function () {
$factory = new PresenterFactory;
$factory->setMapping([
'*' => ['App', 'Module\*', 'Presenter\*'],
Expand All @@ -104,7 +104,7 @@ test('', function () {
});


test('', function () {
test('Empty namespace mapping structure', function () {
$factory = new PresenterFactory;
$factory->setMapping([
'*' => ['', '*', '*'],
Expand All @@ -113,7 +113,8 @@ test('', function () {
});


Assert::exception(
testException(
'Invalid mapping mask validation',
function () {
$factory = new PresenterFactory;
$factory->setMapping([
Expand Down
4 changes: 2 additions & 2 deletions tests/Application/Request.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ use Tester\Assert;
require __DIR__ . '/../bootstrap.php';


test('', function () {
test('Request parameters with null values', function () {
$request = new Request('Homepage', 'GET', ['a' => 1, 'b' => null]);

Assert::same(1, $request->getParameter('a'));
Assert::same(null, $request->getParameter('b'));
});


test('', function () {
test('POST parameters retrieval', function () {
$request = new Request('Homepage', 'GET', [], ['a' => 1, 'b' => null]);

Assert::same(['a' => 1, 'b' => null], $request->getPost());
Expand Down
8 changes: 4 additions & 4 deletions tests/Bridges.DI/ApplicationExtension.invalidLink.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function createCompiler(string $config): DI\Compiler
}


test('', function () {
test('silentLinks enabled with debugger', function () {
$compiler = createCompiler('
application:
silentLinks: yes
Expand All @@ -44,7 +44,7 @@ test('', function () {
});


test('', function () {
test('silentLinks disabled with debugger', function () {
$compiler = createCompiler('
application:
silentLinks: no
Expand All @@ -64,7 +64,7 @@ test('', function () {
});


test('', function () {
test('silentLinks enabled without debugger', function () {
$compiler = createCompiler('
application:
silentLinks: yes
Expand All @@ -84,7 +84,7 @@ test('', function () {
});


test('', function () {
test('silentLinks disabled without debugger', function () {
$compiler = createCompiler('
application:
silentLinks: no
Expand Down
8 changes: 4 additions & 4 deletions tests/Bridges.DI/ApplicationExtension.scan.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require __DIR__ . '/../bootstrap.php';
require __DIR__ . '/files/MyPresenter.php';


test('', function () {
test('default presenter registration', function () {
$compiler = new DI\Compiler;
$compiler->addExtension('application', new ApplicationExtension);

Expand All @@ -30,7 +30,7 @@ test('', function () {
});


test('', function () {
test('scanDirs with filter', function () {
$compiler = new DI\Compiler;
$compiler->addExtension('application', new ApplicationExtension);

Expand All @@ -53,7 +53,7 @@ test('', function () {
});


test('', function () {
test('combined scanDirs and config setup', function () {
$compiler = new DI\Compiler;
$compiler->addExtension('application', new ApplicationExtension(false, [__DIR__ . '/files']));

Expand Down Expand Up @@ -85,7 +85,7 @@ test('', function () {
});


test('', function () {
test('RobotLoader discovery', function () {
$robot = new Nette\Loaders\RobotLoader;
$robot->addDirectory(__DIR__ . '/files');
$robot->setTempDirectory(getTempDir());
Expand Down
6 changes: 3 additions & 3 deletions tests/Bridges.DI/RoutingExtension.cache.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class MyRouter implements Nette\Routing\Router
}


test('', function () {
test('router without cache', function () {
$loader = new DI\Config\Loader;
$config = $loader->load(Tester\FileMock::create('
services:
Expand All @@ -55,7 +55,7 @@ test('', function () {
});


test('', function () {
test('router with cache', function () {
$loader = new DI\Config\Loader;
$config = $loader->load(Tester\FileMock::create('
routing:
Expand All @@ -82,7 +82,7 @@ function myRouterFactory(): Nette\Routing\Router
}


Assert::exception(function () {
testException('non-cacheable router factory', function () {
$loader = new DI\Config\Loader;
$config = $loader->load(Tester\FileMock::create('
routing:
Expand Down
7 changes: 4 additions & 3 deletions tests/Bridges.Latte3/TemplateFactory.customTemplate.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,22 @@ class TemplateMock extends Template
}


test('', function () {
test('default template creation', function () {
$latteFactory = Mockery::mock(LatteFactory::class);
$latteFactory->shouldReceive('create')->andReturn(new Latte\Engine);
$factory = new TemplateFactory($latteFactory);
Assert::type(Template::class, $factory->createTemplate());
});

Assert::exception(
testException(
'13456',
fn() => new TemplateFactory(Mockery::mock(LatteFactory::class), templateClass: stdClass::class),
Nette\InvalidArgumentException::class,
'Class stdClass does not implement Nette\Bridges\ApplicationLatte\Template or it does not exist.',
);


test('', function () {
test('custom template behavior', function () {
$latteFactory = Mockery::mock(LatteFactory::class);
$latteFactory->shouldReceive('create')->andReturn(new Latte\Engine);
$factory = new TemplateFactory($latteFactory, templateClass: TemplateMock::class);
Expand Down
2 changes: 1 addition & 1 deletion tests/Responses/CallbackResponse.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use Tester\Assert;
require __DIR__ . '/../bootstrap.php';


test('', function () {
test('Callback execution on send', function () {
$response = new CallbackResponse(function (Http\IRequest $request, Http\IResponse $response) use (&$ok) {
$ok = true;
});
Expand Down
6 changes: 3 additions & 3 deletions tests/Responses/FileResponse.contentDisposition.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ if (PHP_SAPI === 'cli') {
}


test('', function () {
test('Default attachment content disposition', function () {
$file = __FILE__;
$fileResponse = new FileResponse($file);
$origData = file_get_contents($file);
Expand All @@ -34,7 +34,7 @@ test('', function () {
});


test('', function () {
test('Inline content disposition', function () {
$file = __FILE__;
$fileResponse = new FileResponse($file, forceDownload: false);
$origData = file_get_contents($file);
Expand All @@ -50,7 +50,7 @@ test('', function () {
});


test('', function () {
test('Filename with special characters', function () {
$file = __FILE__;
$fileName = 'žluťoučký kůň.txt';
$fileResponse = new FileResponse($file, $fileName);
Expand Down
Loading

0 comments on commit 486ec41

Please sign in to comment.