Skip to content
This repository has been archived by the owner on Dec 13, 2023. It is now read-only.

Commit

Permalink
Create client factory tests and extension test
Browse files Browse the repository at this point in the history
  • Loading branch information
filipsedivy committed Jan 5, 2020
1 parent fdf8065 commit 3236142
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 0 deletions.
45 changes: 45 additions & 0 deletions tests/cases/ClientFactoryTest.php
@@ -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();
75 changes: 75 additions & 0 deletions tests/cases/DI/EETExtensionTest.php
@@ -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();

0 comments on commit 3236142

Please sign in to comment.