Permalink
Browse files

added Nette\Tester

  • Loading branch information...
dg committed Oct 18, 2012
1 parent b4de8da commit 6c82e777e11c799190117803f2a9c08be25bbaa2
View
@@ -0,0 +1,2 @@
+/tools
+/composer.lock
View
@@ -10,6 +10,12 @@
"homepage": "http://davidgrudl.com"
}
],
+ "require-dev": {
+ "nette/tester": "@dev"
+ },
+ "config": {
+ "vendor-dir": "tools"
+ },
"autoload": {
"classmap": ["dibi/"]
}
@@ -4,17 +4,15 @@
* Test: Cloning of DibiFluent
*
* @author David Grudl
- * @category Dibi
- * @subpackage UnitTests
*/
-require dirname(__FILE__) . '/initialize.php';
+require dirname(__FILE__) . '/bootstrap.php';
-dibi::connect($config['sqlite']);
+dibi::connect($config['sqlite3']);
$fluent = new DibiFluent(dibi::getConnection());
@@ -23,50 +21,23 @@ $dolly = clone $fluent;
$dolly->where('y=1');
$dolly->clause('FOO');
-$fluent->test();
-$dolly->test();
+Assert::same( 'SELECT * FROM [table] WHERE x=1', (string) $fluent );
+Assert::same( 'SELECT * FROM [table] WHERE x=1 AND y=1 FOO', (string) $dolly );
$fluent = dibi::select('id')->from('table')->where('id = %i',1);
$dolly = clone $fluent;
$dolly->where('cd = %i',5);
-$fluent->test();
-$dolly->test();
+Assert::same( 'SELECT [id] FROM [table] WHERE id = 1', (string) $fluent );
+Assert::same( 'SELECT [id] FROM [table] WHERE id = 1 AND cd = 5', (string) $dolly );
$fluent = dibi::select("*")->from("table");
$dolly = clone $fluent;
$dolly->removeClause("select")->select("count(*)");
-$fluent->test();
-$dolly->test();
-
-
-
-__halt_compiler() ?>
-
-------EXPECT------
-SELECT *
-FROM [table]
-WHERE x=1
-
-SELECT *
-FROM [table]
-WHERE x=1 AND y=1 FOO
-
-SELECT [id]
-FROM [table]
-WHERE id = 1
-
-SELECT [id]
-FROM [table]
-WHERE id = 1 AND cd = 5
-
-SELECT *
-FROM [table]
-
-SELECT count(*)
-FROM [table]
+Assert::same( 'SELECT * FROM [table]', (string) $fluent );
+Assert::same( 'SELECT count(*) FROM [table]', (string) $dolly );
View
@@ -1,138 +0,0 @@
-<?php
-
-/**
- * Nette Framework
- *
- * @copyright Copyright (c) 2004 David Grudl
- * @license http://nette.org/license Nette license
- * @link http://nette.org
- * @category Nette
- * @package Nette\Test
- */
-
-
-
-/**
- * Asseratation test helpers.
- *
- * @author David Grudl
- * @package Nette\Test
- */
-class Assert
-{
-
- /**
- * Checks assertation.
- * @param mixed expected
- * @param mixed actual
- * @return void
- */
- public static function same($expected, $actual)
- {
- if ($actual !== $expected) {
- self::note('Failed asserting that ' . self::dump($actual) . ' is not identical to ' . self::dump($expected));
- }
- }
-
-
-
- /**
- * Checks TRUE assertation.
- * @param mixed actual
- * @return void
- */
- public static function true($actual)
- {
- if ($actual !== TRUE) {
- self::note('Failed asserting that ' . self::dump($actual) . ' is not TRUE');
- }
- }
-
-
-
- /**
- * Checks FALSE assertation.
- * @param mixed actual
- * @return void
- */
- public static function false($actual)
- {
- if ($actual !== FALSE) {
- self::note('Failed asserting that ' . self::dump($actual) . ' is not FALSE');
- }
- }
-
-
-
- /**
- * Checks NULL assertation.
- * @param mixed actual
- * @return void
- */
- public static function null($actual)
- {
- if ($actual !== NULL) {
- self::note('Failed asserting that ' . self::dump($actual) . ' is not NULL');
- }
- }
-
-
-
- /**
- * Dumps information about a variable in readable format.
- * @param mixed variable to dump
- * @return void
- */
- private static function dump($var)
- {
- if (is_bool($var)) {
- return $var ? 'TRUE' : 'FALSE';
-
- } elseif ($var === NULL) {
- return "NULL";
-
- } elseif (is_int($var)) {
- return "$var";
-
- } elseif (is_float($var)) {
- return "$var";
-
- } elseif (is_string($var)) {
- return var_export($var, TRUE);
-
- } elseif (is_array($var)) {
- return "array(" . count($var) . ")";
-
- } elseif ($var instanceof Exception) {
- return 'Exception ' . get_class($var) . ': ' . ($var->getCode() ? '#' . $var->getCode() . ' ' : '') . $var->getMessage();
-
- } elseif (is_object($var)) {
- $arr = (array) $var;
- return "object(" . get_class($var) . ") (" . count($arr) . ")";
-
- } elseif (is_resource($var)) {
- return "resource(" . get_resource_type($var) . ")";
-
- } else {
- return "unknown type";
- }
- }
-
-
-
- /**
- * Returns message and file and line from call stack.
- * @param string
- * @return void
- */
- private static function note($message)
- {
- echo $message;
- $trace = debug_backtrace();
- if (isset($trace[1]['file'], $trace[1]['line'])) {
- echo ' in file ' . $trace[1]['file'] . ' on line ' . $trace[1]['line'];
- }
- echo "\n\n";
- }
-
-}
@@ -1,43 +0,0 @@
-
-Nette Test Framework (v0.3)
----------------------------
-<?php
-
-require_once dirname(__FILE__) . '/TestRunner.php';
-
-/**
- * Help
- */
-if (!isset($_SERVER['argv'][1])) { ?>
-Usage:
- php RunTests.php [options] [file or directory]
-
-Options:
- -p <php> Specify PHP-CGI executable to run.
- -c <path> Look for php.ini in directory <path> or use <path> as php.ini.
- -d key=val Define INI entry 'key' with value 'val'.
- -l <path> Specify path to shared library files (LD_LIBRARY_PATH)
- -e <name> Load php environment <name>
- -s Show information about skipped tests
-
-<?php
-}
-
-
-
-/**
- * Execute tests
- */
-try {
- @unlink(dirname(__FILE__) . '/coverage.tmp'); // @ - file may not exist
-
- $manager = new TestRunner;
- $manager->parseConfigFile();
- $manager->parseArguments();
- $res = $manager->run();
- die($res ? 0 : 1);
-
-} catch (Exception $e) {
- echo 'Error: ', $e->getMessage(), "\n";
- die(2);
-}
Oops, something went wrong.

0 comments on commit 6c82e77

Please sign in to comment.