PHP Unit 1st Test.

main
Robert 3 years ago
parent 774b367460
commit 79242846b3
  1. 2
      .gitignore
  2. 32
      UnitTestFiles/Test/FirstTest.php
  3. 13
      UnitTestFiles/Test/setup.php
  4. 2
      cli_cron
  5. 2
      cli_unit_tests.php
  6. 5
      composer.json
  7. 1749
      composer.lock
  8. 1
      phpunit
  9. 8
      phpunit.xml
  10. 1
      src/mockup/controllers/app/home_ctrl.php
  11. 1
      src/mockup/controllers/bills/notices_ctrl.php
  12. 1
      src/mockup/go_text_templates/ctrl.txt
  13. 11
      src/mockup/test_controllers/app/first_ctrl.php
  14. 2
      src/services/live/on_db.php
  15. 98
      src/services/mockup/loadall.php

2
.gitignore vendored

@ -1,5 +1,7 @@
/src/logs/ /src/logs/
tts_framework/ tts_framework/
vendor/
/src/tmp/ /src/tmp/
/public/assets/mockup/js/tts.min.js /public/assets/mockup/js/tts.min.js
/public/assets/mockup/js/tts.min.map /public/assets/mockup/js/tts.min.map
.phpunit.result.cache

@ -0,0 +1,32 @@
<?php
declare(strict_types=1);
namespace UnitTestFiles\Test;
use PHPUnit\Framework\TestCase;
class FirstTest extends TestCase {
public function setUp(): void {
require "setup.php";
setup("/mockup/app/first/returns_true.html");
}
private function do_routes() {
$found_route = \tts\router::execute();
if ($found_route) {
$condition = $found_route;
} else {
$app = new \tts\app();
$condition = $app->load_controller();
}
return $condition;
}
public function testTrueAssetsToTrue() {
$condition = $this->do_routes();
$this->assertTrue($condition);
}
}

@ -0,0 +1,13 @@
<?php
function setup(string $route) {
$p_dir = dirname(__DIR__, 2) . "/src/";
require_once $p_dir . 'before_main.php';
\tts\site_helper::set_all_projects(['mockup', 'ex', 'live']);
\tts\site_helper::set_default_project("mockup");
$PHPUNIT_Testing = true;
\tts\site_helper::init(PROJECT_BASE_DIR, $route, "get", $PHPUNIT_Testing);
require_once PROJECT_BASE_DIR . 'main.php';
}

@ -1,4 +1,4 @@
#!/usr/bin/php #!/usr/bin/env php
<?php <?php
declare(strict_types=1); declare(strict_types=1);

@ -1,4 +1,4 @@
#!/usr/bin/php #!/usr/bin/env php
<?php <?php
declare(strict_types=1); declare(strict_types=1);

@ -0,0 +1,5 @@
{
"require-dev": {
"phpunit/phpunit": "^9.5"
}
}

1749
composer.lock generated

File diff suppressed because it is too large Load Diff

@ -0,0 +1 @@
vendor/phpunit/phpunit/phpunit

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="vendor/autoload.php" colors="true">
<testsuites>
<testsuite name="Application Test Suite">
<directory>UnitTestFiles/Test/</directory>
</testsuite>
</testsuites>
</phpunit>

@ -5,6 +5,7 @@ declare(strict_types=1);
namespace prj\mockup\controllers\app; namespace prj\mockup\controllers\app;
class home_ctrl { class home_ctrl {
public $page_output;
public function index() { public function index() {
$html = new \tts\html_document(); $html = new \tts\html_document();

@ -5,6 +5,7 @@ declare(strict_types=1);
namespace prj\mockup\controllers\bills; namespace prj\mockup\controllers\bills;
class notices_ctrl { class notices_ctrl {
public $page_output;
public function late_payment() { public function late_payment() {
$view_as_pdf = true; $view_as_pdf = true;

@ -3,6 +3,7 @@
namespace prj\{{.Root}}\controllers\{{.Subfolder}}; namespace prj\{{.Root}}\controllers\{{.Subfolder}};
class {{.File}}_ctrl { class {{.File}}_ctrl {
public $page_output;
public function __construct() { public function __construct() {
\tts\main\registry::set('db', \tts\main\registry::get('di')->get_service('db_mocker') ); \tts\main\registry::set('db', \tts\main\registry::get('di')->get_service('db_mocker') );

@ -0,0 +1,11 @@
<?php
namespace prj\mockup\test_controllers\app;
final class first_ctrl {
public function returns_true(): bool {
return true;
}
}

@ -26,7 +26,7 @@ declare(strict_types=1);
try { try {
$pdo_set_time = \tts\common::get_bool(\tts\main\configure::get('database', 'PDO_SET_TIME')); $pdo_set_time = \tts\common::get_bool(\tts\main\configure::get('database', 'PDO_SET_TIME'));
} catch (\tts\Exceptions_common_bool $e) { } catch (\tts\exceptions\Bool_Exception $e) {
echo $e->errorMessage(); echo $e->errorMessage();
} }

@ -1,52 +1,52 @@
<?php <?php
declare(strict_types=1); declare(strict_types=1);
/* /*
* This file is Auto-Generated, Do NOT Modify!!! Please Delete this file to update configuration! * This file is Auto-Generated, Do NOT Modify!!! Please Delete this file to update configuration!
*/ */
/* Contents of : on_html_filter.php */ /* Contents of : on_html_filter.php */
\tts\main\registry::get('di')->register('html_filter', function() { \tts\main\registry::get('di')->register('html_filter', function() {
return new \tts\services\html_filter(); return new \tts\services\html_filter();
}); });
/* Contents of : on_log.php */ /* Contents of : on_log.php */
\tts\main\registry::get('di')->register('log', function(array $arg) { \tts\main\registry::get('di')->register('log', function(array $arg) {
$file_name = null; $file_name = null;
if (isset($arg[0]) && is_string($arg[0])) { if (isset($arg[0]) && is_string($arg[0])) {
$file_name = $arg[0]; // filename $file_name = $arg[0]; // filename
} }
if (isset($arg[1]) && is_int($arg[1])) { if (isset($arg[1]) && is_int($arg[1])) {
$count = $arg[1]; // max count $count = $arg[1]; // max count
return new \tts\services\log($file_name, $count); return new \tts\services\log($file_name, $count);
} }
if (! empty($file_name)) { if (! empty($file_name)) {
return new \tts\services\log($file_name); return new \tts\services\log($file_name);
} }
return new \tts\services\log(); return new \tts\services\log();
}); });
/* Contents of : on_templates.php */ /* Contents of : on_templates.php */
\tts\main\registry::get('di')->register('templates', function(array $arg) { \tts\main\registry::get('di')->register('templates', function(array $arg) {
$file_type = '.tpl'; $file_type = '.tpl';
if (isset($arg[0]) && is_string($arg[0])) { if (isset($arg[0]) && is_string($arg[0])) {
$file_type = $arg[0]; $file_type = $arg[0];
} }
return new \tts\services\liquid_templates($file_type); return new \tts\services\liquid_templates($file_type);
}); });
/* Contents of : on_test_db.php */ /* Contents of : on_test_db.php */
\tts\main\registry::get('di')->register('db_mocker', function($args) { \tts\main\registry::get('di')->register('db_mocker', function($args) {
try { try {
$conn = new \PDO('sqlite::memory:'); $conn = new \PDO('sqlite::memory:');
// set the PDO error mode to exception // set the PDO error mode to exception
$conn->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); $conn->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
return $conn; return $conn;
} catch (\PDOException $e) { } catch (\PDOException $e) {
\tts\exceptions\DB_Exception::customMessage($e); \tts\exceptions\DB_Exception::customMessage($e);
} }
}); });
Loading…
Cancel
Save