This repository has been archived by the owner on Dec 13, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create client factory tests and extension test
- Loading branch information
1 parent
fdf8065
commit 3236142
Showing
2 changed files
with
120 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Tests\Cases; | ||
|
||
use Contributte; | ||
use FilipSedivy; | ||
use Tester; | ||
use Tester\Assert; | ||
|
||
require __DIR__ . '/../bootstrap.php'; | ||
|
||
class ClientFactoryTest extends Tester\TestCase | ||
{ | ||
|
||
public function testCreateFactory(): void | ||
{ | ||
$certificateFactory = new Contributte\EET\CertificateFactory(DATA_DIR . '/EET_CA1_Playground-CZ00000019.p12', 'eet'); | ||
$clientFactory = new Contributte\EET\ClientFactory($certificateFactory, Contributte\EET\Dispatcher::PLAYGROUND_SERVICE, true); | ||
|
||
Assert::type(new Contributte\EET\Dispatcher($certificateFactory->create()), $clientFactory->create()); | ||
} | ||
|
||
public function testCertificateBadPassword(): void | ||
{ | ||
$certificateFactory = new Contributte\EET\CertificateFactory(DATA_DIR . '/EET_CA1_Playground-CZ00000019.p12', 'nothing'); | ||
$clientFactory = new Contributte\EET\ClientFactory($certificateFactory, Contributte\EET\Dispatcher::PLAYGROUND_SERVICE, true); | ||
|
||
Assert::exception(static function () use ($clientFactory): void { | ||
$clientFactory->create(); | ||
}, FilipSedivy\EET\Exceptions\Certificate\CertificateExportFailedException::class); | ||
} | ||
|
||
public function testCertificateNotFound(): void | ||
{ | ||
$certificateFactory = new Contributte\EET\CertificateFactory(DATA_DIR . '/EET_CA1_Playground.p12', 'eet'); | ||
$clientFactory = new Contributte\EET\ClientFactory($certificateFactory, Contributte\EET\Dispatcher::PLAYGROUND_SERVICE, true); | ||
|
||
Assert::exception(static function () use ($clientFactory): void { | ||
$clientFactory->create(); | ||
}, FilipSedivy\EET\Exceptions\Certificate\CertificateNotFoundException::class); | ||
} | ||
|
||
} | ||
|
||
(new ClientFactoryTest())->run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Tests\Cases\DI; | ||
|
||
use Contributte; | ||
use Nette; | ||
use Tester; | ||
use Tester\Assert; | ||
use Tester\FileMock; | ||
|
||
require __DIR__ . '/../../bootstrap.php'; | ||
|
||
class EETExtensionTest extends Tester\TestCase | ||
{ | ||
|
||
public function testNoParameters(): void | ||
{ | ||
$loader = new Nette\DI\ContainerLoader(TEMP_DIR, true); | ||
|
||
Assert::exception(function () use ($loader): void { | ||
$loader->load(function (Nette\DI\Compiler $compiler): void { | ||
$compiler->addExtension('eet', new Contributte\EET\DI\EETExtension()); | ||
}, [getmygid(), __METHOD__]); | ||
}, Nette\DI\InvalidConfigurationException::class); | ||
} | ||
|
||
public function testRequireParameters(): void | ||
{ | ||
$loader = new Nette\DI\ContainerLoader(TEMP_DIR, true); | ||
$class = $loader->load(function (Nette\DI\Compiler $compiler): void { | ||
$compiler->addExtension('eet', new Contributte\EET\DI\EETExtension()); | ||
$compiler->loadConfig(FileMock::create(' | ||
eet: | ||
certificate: | ||
file: Playground.p12 | ||
password: eet | ||
', 'neon')); | ||
}, [getmygid(), __METHOD__]); | ||
|
||
/** @var Nette\DI\Container $container */ | ||
$container = new $class(); | ||
|
||
Assert::type(Contributte\EET\ClientFactory::class, $container->getByType(Contributte\EET\ClientFactory::class)); | ||
Assert::type(Contributte\EET\ReceiptFactory::class, $container->getByType(Contributte\EET\ReceiptFactory::class)); | ||
} | ||
|
||
public function testDefaultReceiptParams(): void | ||
{ | ||
$loader = new Nette\DI\ContainerLoader(TEMP_DIR, true); | ||
$class = $loader->load(function (Nette\DI\Compiler $compiler): void { | ||
$compiler->addExtension('eet', new Contributte\EET\DI\EETExtension()); | ||
$compiler->loadConfig(FileMock::create(' | ||
eet: | ||
certificate: | ||
file: Playground.p12 | ||
password: eet | ||
receipt: | ||
id_provoz: 1234 | ||
dic_popl: CZ1234 | ||
', 'neon')); | ||
}, [getmygid(), __METHOD__]); | ||
|
||
/** @var Nette\DI\Container $container */ | ||
$container = new $class(); | ||
|
||
$receipt = $container->getByType(Contributte\EET\ReceiptFactory::class)->create(); | ||
|
||
Assert::same($receipt->id_provoz, 1234); | ||
Assert::same($receipt->dic_popl, 'CZ1234'); | ||
} | ||
|
||
} | ||
|
||
(new EETExtensionTest())->run(); |