2024-09-24 22:15:15 +04:00
|
|
|
<?php
|
2024-09-30 08:41:47 +04:00
|
|
|
namespace nur\sery {
|
2024-09-24 22:15:15 +04:00
|
|
|
use nulib\tests\TestCase;
|
2024-09-30 08:41:47 +04:00
|
|
|
use nur\sery\impl\config;
|
|
|
|
use nur\sery\impl\myapp;
|
|
|
|
use nur\sery\impl\MyApplication1;
|
|
|
|
use nur\sery\impl\MyApplication2;
|
2024-09-24 22:15:15 +04:00
|
|
|
|
2024-09-30 08:41:47 +04:00
|
|
|
class appTest extends TestCase {
|
2024-09-24 22:15:15 +04:00
|
|
|
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",
|
2024-09-30 08:41:47 +04:00
|
|
|
"appgroup" => null,
|
2024-09-24 22:15:15 +04:00
|
|
|
"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",
|
2024-09-30 08:41:47 +04:00
|
|
|
"appgroup" => null,
|
2024-09-24 22:15:15 +04:00
|
|
|
"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",
|
2024-09-30 08:41:47 +04:00
|
|
|
"appgroup" => null,
|
2024-09-24 22:15:15 +04:00
|
|
|
"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",
|
2024-09-30 08:41:47 +04:00
|
|
|
"appgroup" => null,
|
2024-09-24 22:15:15 +04:00
|
|
|
"name" => "my-application2",
|
|
|
|
"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:41:47 +04:00
|
|
|
namespace nur\sery\impl {
|
|
|
|
|
|
|
|
use nur\sery\app\cli\Application;
|
2024-09-24 22:15:15 +04:00
|
|
|
use nur\sery\os\path;
|
2024-09-30 08:41:47 +04:00
|
|
|
use nur\sery\app;
|
2024-09-24 22:15:15 +04:00
|
|
|
|
|
|
|
class config {
|
2024-09-30 08:41:47 +04:00
|
|
|
const PROJDIR = __DIR__.'/..';
|
2024-09-24 22:15:15 +04:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-30 08:41:47 +04:00
|
|
|
class MyApplication1 extends Application {
|
2024-09-24 22:15:15 +04:00
|
|
|
const PROJDIR = config::PROJDIR;
|
|
|
|
|
|
|
|
function main() {
|
|
|
|
}
|
|
|
|
}
|
2024-09-30 08:41:47 +04:00
|
|
|
class MyApplication2 extends Application {
|
2024-09-24 22:15:15 +04:00
|
|
|
const PROJDIR = null;
|
|
|
|
|
|
|
|
function main() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|