Skip to content
This repository has been archived by the owner on Feb 17, 2020. It is now read-only.

Commit

Permalink
- Updating tests
Browse files Browse the repository at this point in the history
  • Loading branch information
akadlec committed Apr 5, 2017
1 parent b13e468 commit c69c7ce
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 19 deletions.
2 changes: 2 additions & 0 deletions src/IPub/FormSlug/Controls/Slug.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
* @date 08.01.15
*/

declare(strict_types = 1);

namespace IPub\FormSlug\Controls;

use Nette;
Expand Down
2 changes: 2 additions & 0 deletions src/IPub/FormSlug/DI/FormSlugExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
* @date 08.01.15
*/

declare(strict_types = 1);

namespace IPub\FormSlug\DI;

use Nette;
Expand Down
2 changes: 2 additions & 0 deletions src/IPub/FormSlug/Utils/Html.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
* @date 09.01.15
*/

declare(strict_types = 1);

namespace IPub\FormSlug\Utils;

use Nette;
Expand Down
3 changes: 3 additions & 0 deletions tests/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
composer.lock
vendor
tests/temp
3 changes: 3 additions & 0 deletions tests/IPubTests/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
coverage.dat
*.actual
*.expected
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
<?php
/**
* Test: IPub\Forms\SlugInput
* @testCase
*
* @copyright More in license.md
* @license http://www.ipublikuj.eu
* @author Adam Kadlec http://www.ipublikuj.eu
* @package iPublikuj:FormSlug!
* @subpackage Tests
* @since 5.0
* Test: IPub\Forms\SlugInput
* @testCase
*
* @date 10.01.15
* @copyright More in license.md
* @license http://www.ipublikuj.eu
* @author Adam Kadlec http://www.ipublikuj.eu
* @package iPublikuj:FormSlug!
* @subpackage Tests
* @since 5.0
*
* @date 10.01.15
*/

declare(strict_types = 1);

namespace IPubTests\Forms\Slug;

use Nette;
use Nette\Application\UI;
use Nette\Forms;

use Tester;
Expand All @@ -24,10 +27,28 @@ use Tester\Assert;
use IPub;
use IPub\FormSlug;

require __DIR__ . '/../../bootstrap.php';
require __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'bootstrap.php';

class SlugInputTest extends Tester\TestCase
{
/**
* @var UI\ITemplateFactory
*/
private $templateFactory;

/**
* {@inheritdoc}
*/
public function setUp()
{
parent::setUp();

$dic = $this->createContainer();

// Get phone helper from container
$this->templateFactory = $dic->getByType(UI\ITemplateFactory::class);
}

public function testHtml()
{
// Create form control
Expand Down Expand Up @@ -72,18 +93,29 @@ class SlugInputTest extends Tester\TestCase
private function createControl($data = [])
{
$_SERVER['REQUEST_METHOD'] = 'POST';
$_FILES = array();
$_FILES = [];
$_POST = $data;

// Create form
$form = new Forms\Form;
// Create form control
$control = new FormSlug\Controls\Slug;
$control = new FormSlug\Controls\Slug($this->templateFactory);
// Add form control to form
$form->addComponent($control, 'slug');

return $control;
}

/**
* @return Nette\DI\Container
*/
protected function createContainer() : Nette\DI\Container
{
$config = new Nette\Configurator();
$config->setTempDirectory(TEMP_DIR);

return $config->createContainer();
}
}

\run(new SlugInputTest());
\run(new SlugInputTest());
22 changes: 17 additions & 5 deletions tests/IPubTests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,23 +1,35 @@
<?php

require __DIR__ . '/../../vendor/autoload.php';
declare(strict_types = 1);

define('DS', DIRECTORY_SEPARATOR);

require __DIR__ . DS . '..' . DS . '..' . DS . 'vendor' . DS . 'autoload.php';

if (!class_exists('Tester\Assert')) {
echo "Install Nette Tester using `composer update --dev`\n";
exit(1);
}

Tester\Environment::setup();
date_default_timezone_set('Europe/Prague');

// Create temporary directory
define('TEMP_DIR', __DIR__ . '/../tmp/' . (isset($_SERVER['argv']) ? md5(serialize($_SERVER['argv'])) : getmypid()));
Tester\Helpers::purge(TEMP_DIR);
\Tracy\Debugger::$logDirectory = TEMP_DIR;

function id($val) {
$_SERVER = array_intersect_key($_SERVER, array_flip(array(
'PHP_SELF', 'SCRIPT_NAME', 'SERVER_ADDR', 'SERVER_SOFTWARE', 'HTTP_HOST', 'DOCUMENT_ROOT', 'OS', 'argc', 'argv')));
$_SERVER['REQUEST_TIME'] = 1234567890;
$_ENV = $_GET = $_POST = array();

function id($val)
{
return $val;
}

function run(Tester\TestCase $testCase) {
$testCase->run(isset($_SERVER['argv'][1]) ? $_SERVER['argv'][1] : NULL);
}
function run(Tester\TestCase $testCase)
{
$testCase->run();
}

0 comments on commit c69c7ce

Please sign in to comment.