nur-sery/tests/wip/app/app2Test.php

128 lines
3.4 KiB
PHP
Raw Normal View History

2024-09-24 22:15:15 +04:00
<?php
namespace nur\sery\wip\app {
use nulib\tests\TestCase;
use nur\sery\wip\app\impl\config;
2024-09-30 08:13:35 +04:00
use nur\sery\wip\app\impl\myapp;
2024-09-24 22:15:15 +04:00
use nur\sery\wip\app\impl\MyApplication1;
use nur\sery\wip\app\impl\MyApplication2;
class app2Test extends TestCase {
function testWith() {
$projdir = config::get_projdir();
$cwd = getcwd();
2024-09-30 08:13:35 +04:00
myapp::reset();
$app1 = myapp::with(MyApplication1::class);
2024-09-24 22:15:15 +04:00
self::assertSame([
"projdir" => $projdir,
"vendor" => [
"bindir" => "$projdir/vendor/bin",
"autoload" => "$projdir/vendor/autoload.php",
],
"appcode" => "nur-sery",
"cwd" => $cwd,
"datadir" => "$projdir/devel",
"etcdir" => "$projdir/devel/etc",
"vardir" => "$projdir/devel/var",
"logdir" => "$projdir/devel/log",
"profile" => "devel",
"name" => "my-application1",
"title" => null,
], $app1->getParams());
2024-09-30 08:13:35 +04:00
$app2 = myapp::with(MyApplication2::class, $app1);
2024-09-24 22:15:15 +04:00
self::assertSame([
"projdir" => $projdir,
"vendor" => [
"bindir" => "$projdir/vendor/bin",
"autoload" => "$projdir/vendor/autoload.php",
],
"appcode" => "nur-sery",
"cwd" => $cwd,
"datadir" => "$projdir/devel",
"etcdir" => "$projdir/devel/etc",
"vardir" => "$projdir/devel/var",
"logdir" => "$projdir/devel/log",
"profile" => "devel",
"name" => "my-application2",
"title" => null,
], $app2->getParams());
}
function testInit() {
$projdir = config::get_projdir();
$cwd = getcwd();
2024-09-30 08:13:35 +04:00
myapp::reset();
myapp::init(MyApplication1::class);
2024-09-24 22:15:15 +04:00
self::assertSame([
"projdir" => $projdir,
"vendor" => [
"bindir" => "$projdir/vendor/bin",
"autoload" => "$projdir/vendor/autoload.php",
],
"appcode" => "nur-sery",
"cwd" => $cwd,
"datadir" => "$projdir/devel",
"etcdir" => "$projdir/devel/etc",
"vardir" => "$projdir/devel/var",
"logdir" => "$projdir/devel/log",
"profile" => "devel",
"name" => "my-application1",
"title" => null,
2024-09-30 08:13:35 +04:00
], myapp::get()->getParams());
2024-09-24 22:15:15 +04:00
2024-09-30 08:13:35 +04:00
myapp::init(MyApplication2::class);
2024-09-24 22:15:15 +04:00
self::assertSame([
"projdir" => $projdir,
"vendor" => [
"bindir" => "$projdir/vendor/bin",
"autoload" => "$projdir/vendor/autoload.php",
],
"appcode" => "nur-sery",
"cwd" => $cwd,
"datadir" => "$projdir/devel",
"etcdir" => "$projdir/devel/etc",
"vardir" => "$projdir/devel/var",
"logdir" => "$projdir/devel/log",
"profile" => "devel",
"name" => "my-application2",
"title" => null,
2024-09-30 08:13:35 +04:00
], myapp::get()->getParams());
2024-09-24 22:15:15 +04:00
}
}
}
namespace nur\sery\wip\app\impl {
use nur\cli\Application2;
use nur\sery\os\path;
2024-09-30 08:13:35 +04:00
use nur\sery\app\app;
2024-09-24 22:15:15 +04:00
class config {
const PROJDIR = __DIR__.'/../../..';
static function get_projdir(): string {
return path::abspath(self::PROJDIR);
}
}
2024-09-30 08:13:35 +04:00
class myapp extends app {
2024-09-24 22:15:15 +04:00
static function reset(): void {
self::$app = null;
}
}
class MyApplication1 extends Application2 {
const PROJDIR = config::PROJDIR;
function main() {
}
}
class MyApplication2 extends Application2 {
const PROJDIR = null;
function main() {
}
}
}