Skip to content

Commit

Permalink
~
Browse files Browse the repository at this point in the history
  • Loading branch information
goghcrow committed Jun 2, 2017
1 parent d44a3b3 commit 2aaff9a
Show file tree
Hide file tree
Showing 120 changed files with 8,216 additions and 1 deletion.
1 change: 0 additions & 1 deletion .gitignore
Expand Up @@ -36,4 +36,3 @@ composer.lock
/vendor
*.iml
!test/bootstrap.php
test
52 changes: 52 additions & 0 deletions test/Foundation/Container/ContainerTest.php
@@ -0,0 +1,52 @@
<?php
/**
* Created by IntelliJ IDEA.
* User: winglechen
* Date: 16/5/7
* Time: 00:23
*/

namespace Zan\Framework\Test\Foundation\Container;

use Zan\Framework\Foundation\Container\Container;
use Zan\Framework\Test\Foundation\Container\Stub\Demo;
use Zan\Framework\Test\Foundation\Container\Stub\Singleton;

class ContainerTest extends \TestCase
{
public function testMakeWork()
{
$container = new Container();

$demoInstance = $container->make(Demo::class,[0,1]);
$this->assertInstanceOf(Demo::class, $demoInstance, 'Container make instance failed');
$this->assertEquals(0, $demoInstance->getArg0(), 'demoInstance made by container getArg0 failed');
$this->assertEquals(1, $demoInstance->getArg1(), 'demoInstance made by container getArg1 failed');
}

public function testMakeSharedInstanceWork()
{
$container = new Container();

$singleton = $container->make(Singleton::class,['zan'],true);
$this->assertInstanceOf(Singleton::class,$singleton,'container make Singleton fail');
$this->assertEquals('zan', $singleton->getUid(), 'singleton made by container getUid fail');

$singleton = $container->make(Singleton::class,['zanxxxx'],true);
$this->assertInstanceOf(Singleton::class,$singleton,'container share Singleton fail');
$this->assertEquals('zan', $singleton->getUid(), 'container share singleton fail');
}

public function testSingletonWork()
{
$container = new Container();

$singleton = $container->make(Singleton::class,['zan']);
$this->assertInstanceOf(Singleton::class,$singleton,'container make Singleton fail');
$this->assertEquals('zan', $singleton->getUid(), 'singleton made by container getUid fail');

$singleton = $container->make(Singleton::class,['zanxxxx']);
$this->assertInstanceOf(Singleton::class,$singleton,'container share Singleton fail');
$this->assertEquals('zanxxxx', $singleton->getUid(), 'container share singleton fail');
}
}
40 changes: 40 additions & 0 deletions test/Foundation/Container/Stub/Demo.php
@@ -0,0 +1,40 @@
<?php
/**
* Created by IntelliJ IDEA.
* User: winglechen
* Date: 16/5/7
* Time: 00:26
*/

namespace Zan\Framework\Test\Foundation\Container\Stub;


class Demo
{
private $arg0;
private $arg1;

public function __construct($arg0, $arg1)
{

$this->arg0 = $arg0;
$this->arg1 = $arg1;
}

/**
* @return mixed
*/
public function getArg0()
{
return $this->arg0;
}

/**
* @return mixed
*/
public function getArg1()
{
return $this->arg1;
}

}
28 changes: 28 additions & 0 deletions test/Foundation/Container/Stub/Singleton.php
@@ -0,0 +1,28 @@
<?php
/**
* Created by IntelliJ IDEA.
* User: winglechen
* Date: 16/5/7
* Time: 00:43
*/

namespace Zan\Framework\Test\Foundation\Container\Stub;


class Singleton
{
private $uid;

public function __construct($uid)
{
$this->uid = $uid;
}

/**
* @return mixed
*/
public function getUid()
{
return $this->uid;
}
}
29 changes: 29 additions & 0 deletions test/Foundation/Core/ConfigLoaderTest.php
@@ -0,0 +1,29 @@
<?php
/**
* Created by PhpStorm.
* User: heize
* Date: 16/3/3
* Time: 上午10:53
*/
namespace Zan\Framework\Test\Foundation\Core;

use Zan\Framework\Foundation\Core\ConfigLoader;

class ConfigLoaderTest extends \TestCase {

private $path;

public function setUp()
{
$this->path = __DIR__ . '/config/test';
}

public function test(){
$config = new ConfigLoader();
$result = $config->load($this->path);
$this->assertEquals('test', $result['a']['config'], 'ConfigLoader::load fail');
$this->assertEquals('pf', $result['pf']['b']['db'], 'ConfigLoader::load fail');
$this->assertEquals('pf', $result['pf']['a']['a'], 'ConfigLoader::load fail');
$this->assertEquals('test', $result['pf']['b']['test'], 'ConfigLoader::load fail');
}
}
59 changes: 59 additions & 0 deletions test/Foundation/Core/ConfigTest.php
@@ -0,0 +1,59 @@
<?php
/**
* Created by IntelliJ IDEA.
* User: winglechen
* Date: 15/12/18
* Time: 17:54
*/

namespace Zan\Framework\Test\Foundation\Core;

use Zan\Framework\Foundation\Core\Config;
use Zan\Framework\Foundation\Core\RunMode;
use Zan\Framework\Foundation\Core\Path;

class ConfigTest extends \TestCase
{
private $configPath;
private $config;
private $runMode;

public function setUp()
{
$path = __DIR__ . '/config/';
$this->configPath = Path::getConfigPath();
Path::setConfigPath($path);
$this->runMode = RunMode::get();
RunMode::set('test');
$config = new Config();
$this->config = $this->getProperty($config, "configMap");
Config::init();
}

public function tearDown()
{
$config = new Config();
$this->setPropertyValue($config, "configMap", $this->config);
RunMode::set($this->runMode);
Path::setConfigPath($this->configPath);
}

public function testGetConfigWork()
{
$data = Config::get('a.share');
$this->assertEquals('share', $data, 'Config::get share get failed');
$data = Config::get('a.config');
$this->assertEquals('test', $data, 'Config::get share get failed');
$data = Config::get('pf.b.test');
$this->assertEquals('test', $data, 'Config::get share get failed');
$data = Config::get('pf.b.db');
$this->assertEquals('pf', $data, 'Config::get share get failed');
Config::set('pf.b.new','new');
$data = Config::get('pf.b.new');
$this->assertEquals('new', $data, 'Config::set failed');
Config::set('pf','delete');
$data = Config::get('pf');
$this->assertEquals('delete', $data, 'Config::set failed');
}

}
10 changes: 10 additions & 0 deletions test/Foundation/Core/config/online/a.php
@@ -0,0 +1,10 @@
<?php
/**
* Created by PhpStorm.
* User: heize
* Date: 16/3/3
* Time: 下午4:59
*/
return [
'config' => 'online',
];
16 changes: 16 additions & 0 deletions test/Foundation/Core/config/online/pf.php
@@ -0,0 +1,16 @@
<?php
/**
* Created by IntelliJ IDEA.
* User: winglechen
* Date: 15/12/18
* Time: 18:00
*/

return [
'b' => [
'test' => 'online',
'db' => 'online'
],
'evn' => 'online',
'a' => 'online',
];
12 changes: 12 additions & 0 deletions test/Foundation/Core/config/online/pf/a.php
@@ -0,0 +1,12 @@
<?php
/**
* Created by IntelliJ IDEA.
* User: winglechen
* Date: 15/12/18
* Time: 18:00
*/

return [
'test' => 'pf',
'a' => 'pf',
];
10 changes: 10 additions & 0 deletions test/Foundation/Core/config/online/pf/b.php
@@ -0,0 +1,10 @@
<?php
/**
* Created by PhpStorm.
* User: heize
* Date: 16/3/4
* Time: 下午2:24
*/
return [
'db' => 'pf'
];
12 changes: 12 additions & 0 deletions test/Foundation/Core/config/share/a.php
@@ -0,0 +1,12 @@
<?php
/**
* Created by IntelliJ IDEA.
* User: winglechen
* Date: 15/12/18
* Time: 18:00
*/

return [
'config' => 'share',
'share' => 'share'
];
10 changes: 10 additions & 0 deletions test/Foundation/Core/config/test/a.php
@@ -0,0 +1,10 @@
<?php
/**
* Created by PhpStorm.
* User: heize
* Date: 16/3/3
* Time: 下午4:59
*/
return [
'config' => 'test',
];
16 changes: 16 additions & 0 deletions test/Foundation/Core/config/test/pf.php
@@ -0,0 +1,16 @@
<?php
/**
* Created by IntelliJ IDEA.
* User: winglechen
* Date: 15/12/18
* Time: 18:00
*/

return [
'b' => [
'test' => 'test',
'db' => 'test'
],
'evn' => 'test',
'a' => 'test',
];
12 changes: 12 additions & 0 deletions test/Foundation/Core/config/test/pf/a.php
@@ -0,0 +1,12 @@
<?php
/**
* Created by IntelliJ IDEA.
* User: winglechen
* Date: 15/12/18
* Time: 18:00
*/

return [
'test' => 'pf',
'a' => 'pf',
];
10 changes: 10 additions & 0 deletions test/Foundation/Core/config/test/pf/b.php
@@ -0,0 +1,10 @@
<?php
/**
* Created by PhpStorm.
* User: heize
* Date: 16/3/4
* Time: 下午2:24
*/
return [
'db' => 'pf'
];
21 changes: 21 additions & 0 deletions test/Foundation/Coroutine/Base.php
@@ -0,0 +1,21 @@
<?php
/**
* Created by IntelliJ IDEA.
* User: winglechen
* Date: 16/3/17
* Time: 14:44
*/

namespace Zan\Framework\Test\Foundation\Coroutine;


use Zan\Framework\Foundation\Coroutine\Task;

class Base extends \TestCase{
public function testTaskWork()
{
$coroutine = $this->step();

Task::execute($coroutine);
}
}

0 comments on commit 2aaff9a

Please sign in to comment.