diff --git a/UnitTestFiles/Test/FirstTest.php b/UnitTestFiles/Test/FirstTest.php index 37f8cf2..ba8e24f 100644 --- a/UnitTestFiles/Test/FirstTest.php +++ b/UnitTestFiles/Test/FirstTest.php @@ -6,27 +6,23 @@ namespace UnitTestFiles\Test; use PHPUnit\Framework\TestCase; class FirstTest extends TestCase { + private $setup; - 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; + protected function setUp(): void { + require_once "tts_setup.php"; + $this->setup = \testing\tts_setup::get_instance(); } public function testTrueAssetsToTrue() { - $condition = $this->do_routes(); + $this->setup::test_route("/mockup/app/first/returns_true.html"); + $condition = $this->setup::do_routes(); $this->assertTrue($condition); } + public function testAnotherRouteAssetsToTrue() { + $this->setup::test_route("/mockup/app/first/same.html"); + $condition = $this->setup::do_routes(); + $this->assertTrue($condition); + } + } \ No newline at end of file diff --git a/UnitTestFiles/Test/SecondTest.php b/UnitTestFiles/Test/SecondTest.php new file mode 100644 index 0000000..6e06bb1 --- /dev/null +++ b/UnitTestFiles/Test/SecondTest.php @@ -0,0 +1,29 @@ +setup = \testing\tts_setup::get_instance(); + } + + public function testIdAssetsToId() { + $this->setup::test_route("mockup/example/10"); + $condition = $this->setup::do_routes(); + $this->assertEquals($condition, 10); + } + + public function testAnotherRouteAssetsToTrue() { + $this->setup::test_route("/mockup/app/first/not_same.html"); + $condition = $this->setup::do_routes(); + $this->assertFalse($condition); + } + +} \ No newline at end of file diff --git a/UnitTestFiles/Test/setup.php b/UnitTestFiles/Test/setup.php deleted file mode 100644 index 4585cf6..0000000 --- a/UnitTestFiles/Test/setup.php +++ /dev/null @@ -1,13 +0,0 @@ -setup(); + } + + // The object is created from within the class itself + // only if the class has no instance. + public static function get_instance() { + if (self::$instance == null) { + self::$instance = new tts_setup(); + } + + return self::$instance; + } + + private static function setup(): void { + $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"); + + \tts\site_helper::init(PROJECT_BASE_DIR, "", "get", true); + + require_once PROJECT_BASE_DIR . 'main.php'; + } + + public static function test_route(string $route): void { + $PHPUNIT_Testing = true; + \tts\site_helper::init(PROJECT_BASE_DIR, $route, "get", $PHPUNIT_Testing); + } + + public static function do_routes() { + $returned_route = \tts\router::execute(); + + if ($returned_route["found"] === true) { + $condition = $returned_route["returned"]; + } else { + $app = new \tts\app(); + $condition = $app->load_controller(); + } + return $condition; + } + +} diff --git a/cli_cron b/cli_cron index e9a386f..d77601f 100755 --- a/cli_cron +++ b/cli_cron @@ -21,9 +21,9 @@ if (\tts\console_app::is_cli() === false) { echo 'Starting...' . PHP_EOL; -$found_route = \tts\router::execute(); +$returned_route = \tts\router::execute(); -if (!$found_route) { +if ($returned_route["found"] === false) { $app = new \tts\app(); $app->load_controller(); } \ No newline at end of file diff --git a/cli_unit_tests.php b/cli_unit_tests.php deleted file mode 100755 index f86d327..0000000 --- a/cli_unit_tests.php +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/env php -load_controller(); -} \ No newline at end of file diff --git a/public/main.page b/public/main.page index ec93ebf..70beffd 100644 --- a/public/main.page +++ b/public/main.page @@ -11,9 +11,9 @@ $PHPUNIT_Testing = false; require '../src/main.php'; -$found_route = \tts\router::execute(); +$returned_route = \tts\router::execute(); -if (!$found_route) { +if ($returned_route["found"] === false) { $app = new \tts\app(); $app->load_controller(); } \ No newline at end of file diff --git a/src/mockup/cli_controllers/app/home_ctrl.php b/src/mockup/cli_controllers/app/home_ctrl.php index 834a88a..ac752bd 100644 --- a/src/mockup/cli_controllers/app/home_ctrl.php +++ b/src/mockup/cli_controllers/app/home_ctrl.php @@ -13,5 +13,9 @@ class home_ctrl { public function name_demo() { echo "Name Demo CLI..."; } + + public function test($id) { + echo "ID: $id"; + } } \ No newline at end of file diff --git a/src/mockup/routes/cli_routes.php b/src/mockup/routes/cli_routes.php index 20ca86a..cf86407 100644 --- a/src/mockup/routes/cli_routes.php +++ b/src/mockup/routes/cli_routes.php @@ -5,10 +5,10 @@ declare(strict_types=1); namespace prj\mockup\routes; use \tts\router as Router; -class routes { +class cli_routes { public static function get() { - Router::get("mockup/example/{id}?", "prj\mockup\cli_controllers\app\home_ctrl@test"); + Router::get('mockup/example/{id}?', 'prj\mockup\cli_controllers\app\home_ctrl@test'); //Router::route("mockup/app/home/name_demo.html", "prj\mockup\controllers\app\home_ctrl@name_demo"); } diff --git a/src/mockup/routes/routes.php b/src/mockup/routes/routes.php index ff9c444..30bb43b 100644 --- a/src/mockup/routes/routes.php +++ b/src/mockup/routes/routes.php @@ -8,7 +8,7 @@ use \tts\router as Router; class routes { public static function get() { - Router::get("mockup/example/{id}?", "prj\mockup\controllers\app\home_ctrl@test"); + Router::get('mockup/example/{id}?', 'prj\mockup\controllers\app\home_ctrl@test'); //Router::route("mockup/app/home/name_demo.html", "prj\mockup\controllers\app\home_ctrl@name_demo"); } diff --git a/src/mockup/routes/test_routes.php b/src/mockup/routes/test_routes.php index c7d8df7..c6c0143 100644 --- a/src/mockup/routes/test_routes.php +++ b/src/mockup/routes/test_routes.php @@ -5,11 +5,10 @@ declare(strict_types=1); namespace prj\mockup\routes; use \tts\router as Router; -class routes { - +class test_routes { + public static function get() { - Router::get("mockup/example/{id}?", "prj\mockup\test_controllers\app\home_ctrl@test"); - //Router::route("mockup/app/home/name_demo.html", "prj\mockup\controllers\app\home_ctrl@name_demo"); + Router::get('mockup/example/{id}?', 'prj\mockup\test_controllers\app\first_ctrl@example'); } } \ No newline at end of file diff --git a/src/mockup/test_controllers/app/first_ctrl.php b/src/mockup/test_controllers/app/first_ctrl.php index 9b62c20..4595c86 100644 --- a/src/mockup/test_controllers/app/first_ctrl.php +++ b/src/mockup/test_controllers/app/first_ctrl.php @@ -3,9 +3,21 @@ namespace prj\mockup\test_controllers\app; final class first_ctrl { - + public function returns_true(): bool { return true; } + public function same(): bool { + return true; + } + + public function not_same(): bool { + return false; + } + + public function example($id) { + return $id; + } + } \ No newline at end of file