├── tests
├── common
│ ├── 009Test.phtml
│ ├── 053Test_3.inc
│ ├── 049Test_6.inc
│ ├── 049Test_5.inc
│ ├── 048Test_5.inc
│ ├── 034Test.inc
│ ├── 067Test_2.inc
│ ├── 050Test_2.inc
│ ├── 061Test_2.inc
│ ├── 079Test_2.inc
│ ├── 083Test_1.inc
│ ├── multi-section.ini
│ ├── 053Test_2.inc
│ ├── 059Test_1.inc
│ ├── 049Test_1.inc
│ ├── 050Test_1.inc
│ ├── 060Test_2.inc
│ ├── 048Test_1.inc
│ ├── 053Test_1.inc
│ ├── 061Test_1.inc
│ ├── 049Test_4.inc
│ ├── 067Test_1.inc
│ ├── 059Test_2.inc
│ ├── 079Test_1.inc
│ ├── 048Test_4.inc
│ ├── 048Test_2.inc
│ ├── configs
│ │ ├── system.ini
│ │ ├── simple.ini
│ │ ├── p010_simple.ini
│ │ ├── p032_simple.ini
│ │ ├── p044_simple.ini
│ │ └── p055_simple.ini
│ ├── 049Test_2.inc
│ ├── 060Test_1.inc
│ ├── 048Test_3.inc
│ ├── 049Test_3.inc
│ └── build.inc
├── bootstrap.php
├── P014Test.php
├── P001Test.php
├── P017Test.php
├── P035Test.php
├── P047Test.php
├── Base.php
├── P071Test.php
├── P085Test.php
├── P015Test.php
├── P040Test.php
├── P068Test.php
├── P081Test.php
├── P0bug61493Test.php
├── P009Test.php
├── P004Test.php
├── P034Test.php
├── P032Test.php
├── P029Test.php
├── P028Test.php
├── P044Test.php
├── P056Test.php
├── P057Test.php
├── P058Test.php
├── P055Test.php
├── P030Test.php
├── P054Test.php
├── P0issue134Test.php
├── P079Test.php
├── P021Test.php
├── P074Test.php
├── P070Test.php
├── P082Test.php
├── P031Test.php
├── P051Test.php
├── P019Test.php
├── P026Test.php
├── P066Test.php
├── P038Test.php
├── P011Test.php
├── P083Test.php
├── P046Test.php
├── P062Test.php
├── P084Test.php
├── P006Test.php
├── P050Test.php
├── P037Test.php
├── P024Test.php
├── P012Test.php
├── P075Test.php
├── P078Test.php
├── P060Test.php
├── P025Test.php
├── P069Test.php
├── P061Test.php
├── P065Test.php
├── P039Test.php
├── P059Test.php
├── P073Test.php
├── P077Test.php
├── P067Test.php
├── P005Test.php
├── P027Test.php
├── P042Test.php
├── P016Test.php
├── P053Test.php
├── P022Test.php
├── P020Test.php
├── P076Test.php
├── P045Test.php
├── P049Test.php
├── P003Test.php
├── P063Test.php
├── P023Test.php
├── P064Test.php
├── P052Test.php
├── P048Test.php
├── P0bug62702Test.php
├── P072Test.php
├── P018Test.php
├── P0bug63438Test.php
├── P007Test.php
├── P008Test.php
├── P002Test.php
├── P033Test.php
├── P041Test.php
└── P036Test.php
├── docs
├── logo.png
├── yaf_php_auto.gif
└── yaf_php_tip.gif
├── .gitignore
├── psr0
├── exception
│ ├── TypeError.php
│ ├── LoadFailed.php
│ ├── RouterFailed.php
│ ├── DispatchFailed.php
│ ├── StartupError.php
│ └── LoadFailed
│ │ ├── Action.php
│ │ ├── Module.php
│ │ ├── View.php
│ │ └── Controller.php
├── responses
│ └── Cli.php
├── Exception.php
├── Bootstrap.php
├── Action.php
├── view
│ └── Interface.php
├── Registry.php
├── Config.php
├── Plugin.php
└── routes
│ ├── Supervar.php
│ ├── Simple.php
│ └── Interface.php
├── psr4
├── exception
│ ├── LoadFailed.php
│ ├── TypeError.php
│ ├── RouterFailed.php
│ ├── StartupError.php
│ ├── DispatchFailed.php
│ └── LoadFailed
│ │ ├── View.php
│ │ ├── Action.php
│ │ ├── Module.php
│ │ └── Controller.php
├── responses
│ └── Cli.php
├── Bootstrap.php
├── Action.php
├── view
│ └── Interface.php
├── Exception.php
├── Registry.php
├── Config.php
├── Plugin.php
└── routes
│ ├── Supervar.php
│ └── Interface.php
├── .travis.yml
├── composer.json
├── phpunit.xml
├── LICENSE
└── README.md
/tests/common/009Test.phtml:
--------------------------------------------------------------------------------
1 | hello
2 |
--------------------------------------------------------------------------------
/tests/common/053Test_3.inc:
--------------------------------------------------------------------------------
1 | =$name?>
2 |
--------------------------------------------------------------------------------
/tests/common/049Test_6.inc:
--------------------------------------------------------------------------------
1 | catched: =$msg?>
2 |
--------------------------------------------------------------------------------
/tests/common/049Test_5.inc:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/docs/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yinggaozhen/yaf-php-doc/HEAD/docs/logo.png
--------------------------------------------------------------------------------
/tests/common/048Test_5.inc:
--------------------------------------------------------------------------------
1 |
5 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | \.idea
2 | vendor
3 | composer\.lock
4 | *\.out
5 | *\.swp
6 | test
7 | tmp_build
8 |
--------------------------------------------------------------------------------
/docs/yaf_php_auto.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yinggaozhen/yaf-php-doc/HEAD/docs/yaf_php_auto.gif
--------------------------------------------------------------------------------
/docs/yaf_php_tip.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yinggaozhen/yaf-php-doc/HEAD/docs/yaf_php_tip.gif
--------------------------------------------------------------------------------
/tests/common/034Test.inc:
--------------------------------------------------------------------------------
1 |
7 | =$name?>
8 |
--------------------------------------------------------------------------------
/tests/common/067Test_2.inc:
--------------------------------------------------------------------------------
1 | _view->name = 'custom view';
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/tests/common/059Test_1.inc:
--------------------------------------------------------------------------------
1 | returnResponse(true);
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/tests/common/049Test_1.inc:
--------------------------------------------------------------------------------
1 | _view->msg = $exception->getMessage();
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/tests/common/050Test_1.inc:
--------------------------------------------------------------------------------
1 | returnResponse(true);
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/tests/common/060Test_2.inc:
--------------------------------------------------------------------------------
1 | _view->obj = $obj;
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/tests/common/048Test_1.inc:
--------------------------------------------------------------------------------
1 | getMessage());
8 | return false;
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/tests/bootstrap.php:
--------------------------------------------------------------------------------
1 | setView(new SimpleView(YAF_TEST_APPLICATION_PATH . '/views'));
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/tests/common/061Test_1.inc:
--------------------------------------------------------------------------------
1 | forward('dummy');
8 | }
9 |
10 | public function dummyAction()
11 | {
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/psr0/exception/TypeError.php:
--------------------------------------------------------------------------------
1 | 'actions/sub.php',
7 | ];
8 |
9 | public function indexAction()
10 | {
11 | var_dump($this->forward('sub'));
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/psr4/exception/LoadFailed.php:
--------------------------------------------------------------------------------
1 | flushInstantly(true);
8 | }
9 |
10 | public function indexAction()
11 | {
12 | var_dump($this->_view->getScriptPath());
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/tests/common/079Test_1.inc:
--------------------------------------------------------------------------------
1 | registerLocalNamespace('Test');
12 | \Yaf\Registry::set('test', new Test079());
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | sudo: false
2 | language: php
3 |
4 | php:
5 | - 7.1
6 | - 7.2
7 |
8 | cache:
9 | directories:
10 | - $HOME/.composer/cache
11 |
12 |
13 | before_install:
14 | - travis_retry composer self-update
15 |
16 | install:
17 | - composer install
18 |
19 | before_script:
20 | - composer test --coverage-clover=coverage.xml --configuration=phpunit.xml
21 |
22 |
23 |
--------------------------------------------------------------------------------
/tests/P014Test.php:
--------------------------------------------------------------------------------
1 | assertFalse(extension_loaded("yaf"));
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/tests/common/048Test_4.inc:
--------------------------------------------------------------------------------
1 | application->dispatcher->catchException);
15 | $this->getView()->assignRef('ref', $value);
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/tests/P017Test.php:
--------------------------------------------------------------------------------
1 | getConfig());
10 | }
11 |
12 | /**
13 | * @param \Yaf\Dispatcher $dispatcher
14 | * @throws Exception
15 | */
16 | public function _initPlugin(\Yaf\Dispatcher $dispatcher)
17 | {
18 | $dispatcher->registerPlugin(new TestPlugin());
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/tests/P035Test.php:
--------------------------------------------------------------------------------
1 | markTestSkipped();
23 | }
24 |
25 | public function tearDown()
26 | {
27 | parent::setUp();
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/psr4/Bootstrap.php:
--------------------------------------------------------------------------------
1 | assertFalse(extension_loaded("yaf"));
20 | }
21 |
22 | /**
23 | * @param $object
24 | * @param string $property
25 | * @return mixed
26 | * @throws \ReflectionException
27 | */
28 | public function proxyGetProperty($object, $property)
29 | {
30 | return \YP\internalPropertyGet($object, $property);
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/tests/P071Test.php:
--------------------------------------------------------------------------------
1 | assertFalse($new->valid());
26 | }
27 |
28 | public function tearDown()
29 | {
30 | parent::setUp();
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/tests/P085Test.php:
--------------------------------------------------------------------------------
1 | getRaw();
26 |
27 | $this->markTestSkipped();
28 | }
29 |
30 | public function tearDown()
31 | {
32 | parent::setUp();
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/tests/common/049Test_2.inc:
--------------------------------------------------------------------------------
1 | getConfig());
10 | }
11 |
12 | /**
13 | * @param \Yaf\Dispatcher $dispatcher
14 | * @throws Exception
15 | */
16 | public function _initPlugin(\Yaf\Dispatcher $dispatcher)
17 | {
18 | $dispatcher->registerPlugin(new TestPlugin());
19 | }
20 |
21 | public function _initReturn(\Yaf\Dispatcher $dispatcher)
22 | {
23 | $dispatcher->returnResponse(true);
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/tests/common/060Test_1.inc:
--------------------------------------------------------------------------------
1 | setErrorHandler(['Bootstrap', 'errorHandler']);
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/tests/P015Test.php:
--------------------------------------------------------------------------------
1 | assertTrue($previous === $exception->getPrevious());
24 | $this->assertSame('Exception', $exception->getMessage());
25 | $this->assertSame(100, $exception->getPrevious()->getCode());
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/tests/P040Test.php:
--------------------------------------------------------------------------------
1 | render(null);
25 | $view->render(0);
26 | $view->render(true);
27 |
28 | $this->assertTrue(true);
29 | }
30 |
31 | public function tearDown()
32 | {
33 | parent::setUp();
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/tests/P068Test.php:
--------------------------------------------------------------------------------
1 | markTestSkipped('multi ini parse incomplete');
19 | }
20 |
21 | /**
22 | * @throws Exception
23 | * @throws \Yaf\Exception\TypeError
24 | */
25 | public function test()
26 | {
27 | $config = new Ini(__DIR__ . '/common/multi-section.ini');
28 | print_r($config->toArray());
29 | }
30 |
31 | public function tearDown()
32 | {
33 | parent::setUp();
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/tests/P081Test.php:
--------------------------------------------------------------------------------
1 | setBody($string);
27 | $response->setBody($string);
28 | $this->assertSame('Jason is a good boy', $response->getBody());
29 | }
30 |
31 | public function tearDown()
32 | {
33 | parent::setUp();
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/tests/P0bug61493Test.php:
--------------------------------------------------------------------------------
1 | 'bar',
26 | ), false);
27 |
28 | unset($config['foo']);
29 | $this->assertSame([], \YP\internalPropertyGet($config, '_config'));
30 | }
31 |
32 | public function tearDown()
33 | {
34 | parent::setUp();
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/tests/P009Test.php:
--------------------------------------------------------------------------------
1 | assign('name', $value);
26 | unset($value);
27 |
28 | $this->assertSame('laruence', $view->get('name'));
29 | $this->assertSame(6, strlen($view->render(__DIR__ . '/common/009Test.phtml')));
30 | $this->assertSame('laruence', $view->name);
31 | $this->assertNull($view->noexists);
32 | }
33 |
34 | public function tearDown()
35 | {
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "yinggaozhen/yaf-php",
3 | "description": "Yaf PHP version",
4 | "type": "yaf-php",
5 | "version": "1.0.0",
6 | "minimum-stability": "dev",
7 | "homepage": "https://github.com/yinggaozhen/yaf-php",
8 | "require" : {
9 | "php" : ">=7.1"
10 | },
11 | "authors": [
12 | {
13 | "name": "Gaozhen Ying",
14 | "email": "yinggaozhen@hotmail.com"
15 | }
16 | ],
17 | "autoload": {
18 | "psr-4": {
19 | },
20 | "classmap": [
21 | "./"
22 | ],
23 | "files": [
24 | "./Yaf.php",
25 | "./psr4/Exception.php",
26 | "./psr4/routes/Interface.php"
27 | ]
28 | },
29 | "scripts": {
30 | "test": "phpunit"
31 | },
32 | "require-dev": {
33 | "phpunit/phpunit": "^6.0"
34 | },
35 | "repositories": {
36 | "packagist": {
37 | "type": "composer",
38 | "url": "https://packagist.phpcomposer.com"
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/tests/P004Test.php:
--------------------------------------------------------------------------------
1 | assertSame('Ageli Platform', Yaf_Registry::get('name'));
24 | $this->assertTrue(Yaf_Registry::has('name'));
25 |
26 | //---------------------------------------
27 |
28 | $name = 'name';
29 | Yaf_Registry::del($name);
30 |
31 | $this->assertNull(Yaf_Registry::get($name));
32 | $this->assertFalse(Yaf_Registry::has($name));
33 | }
34 |
35 | public function tearDown()
36 | {
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/tests/P034Test.php:
--------------------------------------------------------------------------------
1 | assign('entry', ['a', 'b', 'c']);
27 | $actual = $view->eval($tpl, ['name' => 'template']);
28 |
29 | $expect = <<assertSame($expect, $actual);
37 | }
38 |
39 | public function tearDown()
40 | {
41 | parent::setUp();
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/tests/P032Test.php:
--------------------------------------------------------------------------------
1 | assertSame([
30 | 'env' => 'bar',
31 | 'ini' => '',
32 | 'const' => 'Dummy'
33 | ], internalPropertyGet($config, '_config'));
34 | }
35 |
36 | public function tearDown()
37 | {
38 | parent::setUp();
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/tests/P029Test.php:
--------------------------------------------------------------------------------
1 | assign('a', 'b');
25 | $view->assign('b', 'a');
26 | $this->assertSame('b', $view->get('a'));
27 | $this->assertSame([
28 | 'a' => 'b',
29 | 'b' => 'a'
30 | ], $view->get());
31 |
32 | $view->clear('b');
33 | $this->assertSame([
34 | 'a' => 'b'
35 | ], $view->get());
36 | $view->clear();
37 | $this->assertSame([], $view->get());
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/tests/P028Test.php:
--------------------------------------------------------------------------------
1 | assign('name', 'laruence');
29 | $tpl = YAF_TEST_APPLICATION_PATH . '/tpls/foo.phtml';
30 |
31 | file_put_contents($tpl, <<assertSame('okey', $view->render($tpl));
36 | }
37 |
38 | public function tearDown()
39 | {
40 | shutdown();
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/tests/P044Test.php:
--------------------------------------------------------------------------------
1 | assertSame('Yaf\Dispatcher', get_class($b));
32 | }
33 |
34 | public function tearDown()
35 | {
36 | parent::setUp();
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/psr4/Action.php:
--------------------------------------------------------------------------------
1 | _controller;
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/tests/P056Test.php:
--------------------------------------------------------------------------------
1 | throwException(true);
27 | $this->assertTrue(Dispatcher::getInstance()->throwException());
28 | Dispatcher::getInstance()->throwException(false);
29 | $this->assertFalse(Dispatcher::getInstance()->throwException());
30 | }
31 |
32 | public function tearDown()
33 | {
34 | parent::setUp();
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/tests/P057Test.php:
--------------------------------------------------------------------------------
1 | catchException(true);
27 | $this->assertTrue(Dispatcher::getInstance()->catchException());
28 | Dispatcher::getInstance()->catchException(false);
29 | $this->assertFalse(Dispatcher::getInstance()->catchException());
30 | }
31 |
32 | public function tearDown()
33 | {
34 | parent::setUp();
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/tests/P058Test.php:
--------------------------------------------------------------------------------
1 | flushInstantly(true);
27 | $this->assertTrue(Dispatcher::getInstance()->flushInstantly());
28 | Dispatcher::getInstance()->flushInstantly(false);
29 | $this->assertFalse(Dispatcher::getInstance()->flushInstantly());
30 | }
31 |
32 | public function tearDown()
33 | {
34 | parent::setUp();
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/psr0/Action.php:
--------------------------------------------------------------------------------
1 | _controller;
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/tests/P055Test.php:
--------------------------------------------------------------------------------
1 | autoRender(true);
28 | $this->assertTrue(Dispatcher::getInstance()->autoRender());
29 | Dispatcher::getInstance()->autoRender(false);
30 | $this->assertFalse(Dispatcher::getInstance()->autoRender());
31 | }
32 |
33 | public function tearDown()
34 | {
35 | parent::setUp();
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/phpunit.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
14 | ./tests/
15 |
16 |
17 |
18 |
19 | ./
20 |
21 | tests
22 | vendor
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/tests/P030Test.php:
--------------------------------------------------------------------------------
1 | assertTrue(
32 | strncmp(
33 | "There is no section 'ex' in",
34 | $e->getMessage(),
35 | strlen("There is no section 'ex' in")
36 | ) === 0
37 | );
38 | }
39 |
40 | $this->assertTrue($exception);
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/tests/P054Test.php:
--------------------------------------------------------------------------------
1 | assertTrue(stripos($e->getMessage(), 'Argument is not a valid ini file ') !== false);
27 | }
28 | $this->assertTrue($exception);
29 |
30 | $request = new Simple(null);
31 | $this->assertFalse($request->isOptions());
32 |
33 | $config = new Simple([]);
34 | $config->key();
35 | $this->assertSame('okey', 'okey');
36 | }
37 |
38 | public function tearDown()
39 | {
40 | parent::setUp();
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/tests/P0issue134Test.php:
--------------------------------------------------------------------------------
1 | 'index',
28 | 'action' => 'detail',
29 | 'module' => 'kfc'
30 | ]
31 | );
32 | $router->addRoute('kfc/index/detail', $route);
33 | $this->assertSame('/detail/1', $router->getRoute('kfc/index/detail')->assemble([
34 | ':id' => '1',
35 | ]
36 | ));
37 | }
38 |
39 | public function tearDown()
40 | {
41 | parent::setUp();
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/tests/common/configs/simple.ini:
--------------------------------------------------------------------------------
1 | [base]
2 | application.directory=APPLICATION_PATH "/applcation"
3 | name = "base"
4 | array.1 = 1
5 | 5=6
6 | array.name="name"
7 | routes.regex.type="regex"
8 | routes.regex.match="^/ap/(.*)"
9 | routes.regex.route.controller="Index"
10 | routes.regex.route.action="action"
11 | routes.regex.map.0="name"
12 | routes.regex.map.1="name"
13 | routes.regex.map.2="value"
14 | routes.simple.type="simple"
15 | routes.simple.controller="c"
16 | routes.simple.module="m"
17 | routes.simple.action="a"
18 | routes.supervar.type="supervar"
19 | routes.supervar.varname="c"
20 | routes.rewrite.type="rewrite"
21 | routes.rewrite.match="/yaf/:name/:value"
22 | routes.rewrite.route.controller="Index"
23 | routes.rewrite.route.action="action"
24 |
25 | [extra : base ]
26 | value = "2"
27 | name = "extra"
28 | array.name = "new_name"
29 | array.2 = "test"
30 |
31 | [product : extra]
32 |
33 | [nocatch : extra]
34 | application.dispatcher.throwException=Off
35 | application.dispatcher.catchException=yes
36 | routes.rewrite.match="/yaf/:name/:age"
37 |
38 | [envtest]
39 | env=${FOO}
40 | ini=${yaf.directory}
41 | const=FOO
42 |
43 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2019 Gaozhen Ying
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/tests/common/configs/p010_simple.ini:
--------------------------------------------------------------------------------
1 | [base]
2 | application.directory=P010_APPLICATION_PATH "/applcation"
3 | name = "base"
4 | array.1 = 1
5 | 5=6
6 | array.name="name"
7 | routes.regex.type="regex"
8 | routes.regex.match="^/ap/(.*)"
9 | routes.regex.route.controller="Index"
10 | routes.regex.route.action="action"
11 | routes.regex.map.0="name"
12 | routes.regex.map.1="name"
13 | routes.regex.map.2="value"
14 | routes.simple.type="simple"
15 | routes.simple.controller="c"
16 | routes.simple.module="m"
17 | routes.simple.action="a"
18 | routes.supervar.type="supervar"
19 | routes.supervar.varname="c"
20 | routes.rewrite.type="rewrite"
21 | routes.rewrite.match="/yaf/:name/:value"
22 | routes.rewrite.route.controller="Index"
23 | routes.rewrite.route.action="action"
24 |
25 | [extra : base ]
26 | value = "2"
27 | name = "extra"
28 | array.name = "new_name"
29 | array.2 = "test"
30 |
31 | [product : extra]
32 |
33 | [nocatch : extra]
34 | application.dispatcher.throwException=Off
35 | application.dispatcher.catchException=yes
36 | routes.rewrite.match="/yaf/:name/:age"
37 |
38 | [envtest]
39 | env=${FOO}
40 | ini=${yaf.directory}
41 | const=FOO
42 |
43 |
--------------------------------------------------------------------------------
/tests/common/configs/p032_simple.ini:
--------------------------------------------------------------------------------
1 | [base]
2 | application.directory=APPLICATION_PATH "/applcation"
3 | name = "base"
4 | array.1 = 1
5 | 5=6
6 | array.name="name"
7 | routes.regex.type="regex"
8 | routes.regex.match="^/ap/(.*)"
9 | routes.regex.route.controller="Index"
10 | routes.regex.route.action="action"
11 | routes.regex.map.0="name"
12 | routes.regex.map.1="name"
13 | routes.regex.map.2="value"
14 | routes.simple.type="simple"
15 | routes.simple.controller="c"
16 | routes.simple.module="m"
17 | routes.simple.action="a"
18 | routes.supervar.type="supervar"
19 | routes.supervar.varname="c"
20 | routes.rewrite.type="rewrite"
21 | routes.rewrite.match="/yaf/:name/:value"
22 | routes.rewrite.route.controller="Index"
23 | routes.rewrite.route.action="action"
24 |
25 | [extra : base ]
26 | value = "2"
27 | name = "extra"
28 | array.name = "new_name"
29 | array.2 = "test"
30 |
31 | [product : extra]
32 |
33 | [nocatch : extra]
34 | application.dispatcher.throwException=Off
35 | application.dispatcher.catchException=yes
36 | routes.rewrite.match="/yaf/:name/:age"
37 |
38 | [envtest]
39 | env=${P032FOO}
40 | ini=${yaf.directory}
41 | const=P032FOO
42 |
43 |
--------------------------------------------------------------------------------
/tests/common/configs/p044_simple.ini:
--------------------------------------------------------------------------------
1 | [base]
2 | application.directory=P044_APPLICATION_PATH "/applcation"
3 | name = "base"
4 | array.1 = 1
5 | 5=6
6 | array.name="name"
7 | routes.regex.type="regex"
8 | routes.regex.match="^/ap/(.*)"
9 | routes.regex.route.controller="Index"
10 | routes.regex.route.action="action"
11 | routes.regex.map.0="name"
12 | routes.regex.map.1="name"
13 | routes.regex.map.2="value"
14 | routes.simple.type="simple"
15 | routes.simple.controller="c"
16 | routes.simple.module="m"
17 | routes.simple.action="a"
18 | routes.supervar.type="supervar"
19 | routes.supervar.varname="c"
20 | routes.rewrite.type="rewrite"
21 | routes.rewrite.match="/yaf/:name/:value"
22 | routes.rewrite.route.controller="Index"
23 | routes.rewrite.route.action="action"
24 |
25 | [extra : base ]
26 | value = "2"
27 | name = "extra"
28 | array.name = "new_name"
29 | array.2 = "test"
30 |
31 | [product : extra]
32 |
33 | [nocatch : extra]
34 | application.dispatcher.throwException=Off
35 | application.dispatcher.catchException=yes
36 | routes.rewrite.match="/yaf/:name/:age"
37 |
38 | [envtest]
39 | env=${P032FOO}
40 | ini=${yaf.directory}
41 | const=P032FOO
42 |
43 |
--------------------------------------------------------------------------------
/tests/common/configs/p055_simple.ini:
--------------------------------------------------------------------------------
1 | [base]
2 | application.directory=P055_APPLICATION_PATH "/applcation"
3 | name = "base"
4 | array.1 = 1
5 | 5=6
6 | array.name="name"
7 | routes.regex.type="regex"
8 | routes.regex.match="^/ap/(.*)"
9 | routes.regex.route.controller="Index"
10 | routes.regex.route.action="action"
11 | routes.regex.map.0="name"
12 | routes.regex.map.1="name"
13 | routes.regex.map.2="value"
14 | routes.simple.type="simple"
15 | routes.simple.controller="c"
16 | routes.simple.module="m"
17 | routes.simple.action="a"
18 | routes.supervar.type="supervar"
19 | routes.supervar.varname="c"
20 | routes.rewrite.type="rewrite"
21 | routes.rewrite.match="/yaf/:name/:value"
22 | routes.rewrite.route.controller="Index"
23 | routes.rewrite.route.action="action"
24 |
25 | [extra : base ]
26 | value = "2"
27 | name = "extra"
28 | array.name = "new_name"
29 | array.2 = "test"
30 |
31 | [product : extra]
32 |
33 | [nocatch : extra]
34 | application.dispatcher.throwException=Off
35 | application.dispatcher.catchException=yes
36 | routes.rewrite.match="/yaf/:name/:age"
37 |
38 | [envtest]
39 | env=${P055FOO}
40 | ini=${yaf.directory}
41 | const=P055FOO
42 |
43 |
--------------------------------------------------------------------------------
/tests/P079Test.php:
--------------------------------------------------------------------------------
1 | [
28 | 'directory' => YAF_TEST_APPLICATION_PATH,
29 | ],
30 | ];
31 |
32 | file_put_contents(YAF_TEST_APPLICATION_PATH . '/Bootstrap.php', file_get_contents(__DIR__ . '/common/079Test_1.inc'));
33 | file_put_contents(YAF_TEST_APPLICATION_PATH . '/library/Test.php', file_get_contents(__DIR__ . '/common/079Test_2.inc'));
34 |
35 | $app = new \Yaf\Application($config);
36 | $app->bootstrap();
37 | }
38 |
39 | public function tearDown()
40 | {
41 | parent::setUp();
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/tests/common/048Test_3.inc:
--------------------------------------------------------------------------------
1 | getDispatcher()->setErrorHandler('error_handler', E_ALL);
36 | $app->run();
37 | }
38 |
39 | public function tearDown()
40 | {
41 | parent::tearDown();
42 | define('APPLICATION_PATH', null);
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/tests/P074Test.php:
--------------------------------------------------------------------------------
1 | addRoute('simple', $route);
29 |
30 | $this->assertSame('?m=yafmodule&c=yafcontroller&a=yafaction&tkey1=tval1&tkey2=tval2', $router->getRoute('simple')->assemble([
31 | ':a' => 'yafaction',
32 | 'tkey' => 'tval',
33 | ':c' => 'yafcontroller',
34 | ':m' => 'yafmodule'
35 | ],
36 | [
37 | 'tkey1' => 'tval1',
38 | 'tkey2' => 'tval2'
39 | ]
40 | ));
41 | }
42 |
43 | public function tearDown()
44 | {
45 | parent::setUp();
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/tests/P070Test.php:
--------------------------------------------------------------------------------
1 | run();
35 | }
36 | catch (\Exception $e) {
37 | $expection = true;
38 |
39 | // TODO $e->getPrevious()->getMessage()
40 | $this->assertSame('Expects a path to *.ini configuration file as parameter', $e->getMessage());
41 | }
42 |
43 | $this->assertTrue($expection);
44 | }
45 |
46 | public function tearDown()
47 | {
48 | parent::setUp();
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/tests/P082Test.php:
--------------------------------------------------------------------------------
1 | assign('name', 'laruence');
29 | $tpl = YAF_TEST_APPLICATION_PATH . '/tpls/foo.phtml';
30 |
31 | file_put_contents($tpl, <<render($tpl);
39 | $actual = ob_get_contents();
40 | ob_end_clean();
41 |
42 | $this->assertTrue(stripos(error_get_last()['message'], 'Undefined variable: tpl') !== false);
43 | $this->assertSame('laruence', $actual);
44 | }
45 |
46 | public function tearDown()
47 | {
48 | parent::setUp();
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/tests/P031Test.php:
--------------------------------------------------------------------------------
1 | [
26 | 'directory' => realpath(__DIR__),
27 | 'dispatcher' => [
28 | 'defaultRoute' => [
29 | 'type' => 'map',
30 | 'delimiter' => '##',
31 | 'controllerPrefer' => 1,
32 | ],
33 | ],
34 | ],
35 | ];
36 |
37 | $app = new Application($config);
38 | $routes = $app->getDispatcher()->getRouter()->getRoutes()['_default'];
39 |
40 | $this->assertTrue(internalPropertyGet($routes, '_ctl_router'));
41 | $this->assertSame('##', internalPropertyGet($routes, '_delimiter'));
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/tests/P051Test.php:
--------------------------------------------------------------------------------
1 | route($x);
31 |
32 | $x = new Route_Static();
33 | $x->route($x);
34 |
35 | $x = new Rewrite('#^/test#', ['controller' => 'info'], []);
36 | $x->route($x);
37 |
38 | $x = new Supervar('r');
39 | $x->route($x);
40 |
41 | $x = new Regex('#^/test#', ['controller' => 'info'], []);
42 | $x->route($x);
43 |
44 | $this->assertSame('okey', 'okey');
45 | }
46 |
47 | public function tearDown()
48 | {
49 | parent::setUp();
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/tests/P019Test.php:
--------------------------------------------------------------------------------
1 | addConfig(
28 | [
29 | [
30 | 'type' => 'regex',
31 | 'match' => '#^/ap/([^/]*)/*#i',
32 | 'route' => [
33 | [
34 | 'action' => 'ap',
35 | ],
36 | ],
37 | 'map' => [
38 | 1 => 'version',
39 | ]
40 | ]
41 | ]
42 | )->route($request);
43 |
44 | $this->assertSame(0, $router->getCurrentRoute());
45 | $this->assertSame('1.2', $request->getParam('version'));
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/tests/common/build.inc:
--------------------------------------------------------------------------------
1 | setBody('ell')
27 | ->appendBody('o')
28 | ->setBody(' W', 'footer')
29 | ->prependBody('H')
30 | ->appendBody('orld', 'footer');
31 |
32 |
33 | $this->assertSame('Hello', $response->getBody('content'));
34 | $this->assertSame(' World', $response->getBody('footer'));
35 | $this->assertTrue((bool) internalPropertyGet($response, '_sendheader'));
36 | $this->assertFalse((bool) internalPropertyGet($response, '_response_code'));
37 | $this->assertSame('Hello World', (string) $response);
38 | }
39 |
40 | public function tearDown()
41 | {
42 | parent::tearDown();
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/tests/P066Test.php:
--------------------------------------------------------------------------------
1 | addRoute('ap', new Regex("#^/ap/([^/]*)/([^/]*)/*#i", [
29 | 'action' => 'ap',
30 | ], [
31 | 1 => 23432,
32 | 2 => null,
33 | ]
34 | ))->route($request);
35 |
36 | $this->assertSame('ap', $router->getCurrentRoute());
37 | $this->assertNull($request->getParam(1));
38 | $this->assertSame('ap', $request->getActionName());
39 | $this->assertNull($request->getControllerName());
40 | $this->assertNull($request->getParam('name'));
41 | }
42 |
43 | public function tearDown()
44 | {
45 | parent::setUp();
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/tests/P038Test.php:
--------------------------------------------------------------------------------
1 | assign('name', 'laruence');
30 | $tpl = YAF_TEST_APPLICATION_PATH . '/tpls/foo.phtml';
31 |
32 | $html = <<
37 | HTML;
38 |
39 | $exception = false;
40 | file_put_contents($tpl, $html);
41 | try {
42 | echo $view->render($tpl);
43 | } catch (Error $e) {
44 | $exception = true;
45 | $this->assertSame("syntax error, unexpected '}'", $e->getMessage());
46 | }
47 |
48 | $this->assertTrue($exception);
49 | }
50 |
51 | public function tearDown()
52 | {
53 | parent::setUp();
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/tests/P011Test.php:
--------------------------------------------------------------------------------
1 | addRoute('subdir', new Rewrite('/subdir/:name/:version', [
30 | 'action' => 'version',
31 | ]
32 | ))
33 | ->addRoute('ap', new Rewrite('/ap/:version/*', [
34 | 'action' => 'ap',
35 | ]
36 | ))
37 | ->route($request);
38 |
39 | $this->assertSame('ap', $router->getCurrentRoute());
40 | $this->assertSame('1.2', $request->getParam('version'));
41 | $this->assertSame('ap', $request->getActionName());
42 | $this->assertNull($request->getControllerName());
43 | $this->assertSame('value', $request->getParam('name'));
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/tests/P083Test.php:
--------------------------------------------------------------------------------
1 | [
30 | 'directory' => YAF_TEST_APPLICATION_PATH,
31 | ],
32 | ];
33 |
34 | file_put_contents(YAF_TEST_APPLICATION_PATH . '/controllers/Index.php', file_get_contents(__DIR__ . '/common/083Test_1.inc'));
35 | file_put_contents(YAF_TEST_APPLICATION_PATH . '/views/index/index.phtml', 'okey');
36 |
37 | $app = new Application($config);
38 | $response = $app->getDispatcher()->returnResponse(true)->dispatch(new Simple('CLI', 'Index', 'Index', 'index'));
39 | $this->assertSame('okey', $response->getBody());
40 | }
41 |
42 | public function tearDown()
43 | {
44 | parent::setUp();
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/tests/P046Test.php:
--------------------------------------------------------------------------------
1 | [
27 | 'directory' => __DIR__,
28 | 'library' => [
29 | 'directory' => '/tmp',
30 | 'namespace' => 'Foo',
31 | ],
32 | ],
33 | ];
34 |
35 | new Application($config);
36 | $loader = Loader::getInstance();
37 | $this->assertTrue($loader->isLocalName('Foo_Bar'));
38 | $this->assertTrue($loader->isLocalName('Foo'));
39 | $loader->clearLocalNamespace();
40 | $loader->registerLocalNamespace('Bar');
41 | $this->assertFalse($loader->isLocalName('Foo_Bar'));
42 | $this->assertTrue($loader->isLocalName('Bar'));
43 | }
44 |
45 | public function tearDown()
46 | {
47 | parent::setUp();
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/tests/P062Test.php:
--------------------------------------------------------------------------------
1 | assertSame('Expects an absolute path for templates directory', $e->getMessage());
33 | }
34 | $this->assertTrue($exception);
35 |
36 | $config = [
37 | 'application' => [
38 | 'directory' => __DIR__,
39 | ],
40 | ];
41 | $app = new Application($config);
42 |
43 | $view = Dispatcher::getInstance()->initView([]);
44 | $this->assertNull($view->getScriptPath());
45 | }
46 |
47 | public function tearDown()
48 | {
49 | parent::setUp();
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/tests/P084Test.php:
--------------------------------------------------------------------------------
1 | $method());
30 | TestCase::assertSame(1, $request->isGet() + $request->isPost() + $request->isHead()
31 | + $request->isDelete() + $request->isPut() + $request->isOptions()
32 | + $request->isPatch());
33 | }
34 |
35 | checkMethod('GET');
36 | checkMethod('POST');
37 | checkMethod('HEAD');
38 | checkMethod('DELETE');
39 | checkMethod('PUT');
40 | checkMethod('OPTIONS');
41 | checkMethod('PATCH');
42 | }
43 |
44 | public function tearDown()
45 | {
46 | parent::setUp();
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/tests/P006Test.php:
--------------------------------------------------------------------------------
1 | assertTrue($route->route($request));
31 | $this->assertNull($request->module);
32 | $this->assertSame('controller', $request->controller);
33 | $this->assertSame('action', $request->action);
34 | $this->assertSame('Cli', $request->method);
35 | $this->assertSame([
36 | 'name' => 'laruence',
37 | 'age' => 28
38 | ], $request->getParams());
39 | $this->assertSame('/prefix/', $request->getBaseUri());
40 | $this->assertSame('/prefix/controller/action/name/laruence/age/28', $request->getRequestUri());
41 | }
42 |
43 | public function tearDown()
44 | {
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/tests/P050Test.php:
--------------------------------------------------------------------------------
1 | [
29 | 'directory' => YAF_TEST_APPLICATION_PATH,
30 | ],
31 | ];
32 |
33 | file_put_contents(YAF_TEST_APPLICATION_PATH . '/Bootstrap.php', file_get_contents(__DIR__ . '/common/050Test_1.inc'));
34 | file_put_contents(YAF_TEST_APPLICATION_PATH . '/controllers/Index.php', file_get_contents(__DIR__ . '/common/050Test_2.inc'));
35 | file_put_contents(YAF_TEST_APPLICATION_PATH . '/views/index/index.phtml', 'view');
36 |
37 | $app = new Application($config);
38 | $response = $app->bootstrap()->run();
39 | $this->assertSame('view', (string) $response);
40 | }
41 |
42 | public function tearDown()
43 | {
44 | parent::setUp();
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/tests/P037Test.php:
--------------------------------------------------------------------------------
1 | import($dir . '/Dummy.php');
37 | $loader->autoload('Dummy');
38 | }
39 |
40 | public function tearDown()
41 | {
42 | parent::setUp();
43 | @unlink(__DIR__ . '/common/tmp_build/Dummy.php');
44 |
45 | YAF_G('yaf.lowcase_path', YAF_G('bak_lowcase_path'));
46 | YAF_G('yaf.use_spl_autoload', YAF_G('bak_use_spl_autoload'));
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/tests/P024Test.php:
--------------------------------------------------------------------------------
1 | assertSame('/foo', $loader->getLibraryPath());
31 | $this->assertSame('/bar', $loader->getLibraryPath(true));
32 |
33 | $config = [
34 | 'application' => [
35 | 'directory' => realpath(dirname(__FILE__)),
36 | ],
37 | ];
38 |
39 | $app = new Application($config);
40 | $this->assertRegExp('/^[\w\/-]+library$/', $loader->getLibraryPath());
41 | $this->assertSame('/php/global/dir', $loader->getLibraryPath(true));
42 | }
43 |
44 | public function tearDown()
45 | {
46 | parent::tearDown();
47 |
48 | YAF_G('yaf.library', YAF_G('bak_library'));
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/psr0/view/Interface.php:
--------------------------------------------------------------------------------
1 | addRoute('subdir', new Regex('#/subdir/(.*)#',
30 | [
31 | 'action' => 'version',
32 | ],
33 | []
34 | ))
35 | ->addRoute('ap', new Regex('#^/ap/([^/]*)/*#i',
36 | [
37 | 'action' => 'ap',
38 | ],
39 | [
40 | 1 => 'version',
41 | ]
42 | ))->route($request);
43 |
44 | $this->assertSame('ap', $router->getCurrentRoute());
45 | $this->assertSame('1.2', $request->getParam('version'));
46 | $this->assertSame('ap', $request->getActionName());
47 | $this->assertNull($request->getControllerName());
48 | $this->assertNull($request->getParam('name'));
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/psr4/view/Interface.php:
--------------------------------------------------------------------------------
1 | "product", //route to product controller,
31 | ),
32 | array(),
33 | array(),
34 | '/:m/:c/:a'
35 | );
36 |
37 | $router->addRoute("regex", $route);
38 |
39 | $this->assertSame('/module/controller/action?tkey1=tval1&tkey2=tval2',
40 | $router->getRoute('regex')->assemble([
41 | ':m' => 'module',
42 | ':c' => 'controller',
43 | ':a' => 'action'
44 | ],
45 | [
46 | 'tkey1' => 'tval1',
47 | 'tkey2' =>
48 | 'tval2'
49 | ]
50 | )
51 | );
52 | }
53 |
54 | public function tearDown()
55 | {
56 | parent::setUp();
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/tests/P078Test.php:
--------------------------------------------------------------------------------
1 | addRoute('map', $route);
29 |
30 | $this->assertSame('/foo/bar?tkey1=tval1&tkey2=tval2', $router->getRoute('map')->assemble(
31 | array(
32 | ':c' => 'foo_bar'
33 | ),
34 | array(
35 | 'tkey1' => 'tval1',
36 | 'tkey2' => 'tval2'
37 | )
38 | ));
39 |
40 | $route = new Map(true, '_');
41 | $router->addRoute('map', $route);
42 |
43 | $this->assertSame('/foo/bar/_/tkey1/tval1/tkey2/tval2', $router->getRoute('map')->assemble(
44 | array(
45 | ':a' => 'foo_bar'
46 | ),
47 | array(
48 | 'tkey1' => 'tval1',
49 | 'tkey2' => 'tval2'
50 | )
51 | ));
52 | }
53 |
54 | public function tearDown()
55 | {
56 | parent::setUp();
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/tests/P060Test.php:
--------------------------------------------------------------------------------
1 | [
30 | 'directory' => YAF_TEST_APPLICATION_PATH,
31 | ],
32 | ];
33 |
34 | file_put_contents(YAF_TEST_APPLICATION_PATH . '/Bootstrap.php', file_get_contents(__DIR__ . '/common/060Test_1.inc'));
35 | file_put_contents(YAF_TEST_APPLICATION_PATH . '/controllers/Index.php', file_get_contents(__DIR__ . '/common/060Test_2.inc'));
36 | file_put_contents(YAF_TEST_APPLICATION_PATH . "/views/index/index.phtml", "");
37 |
38 | ob_start();
39 | $app = new Application($config);
40 | $response = $app->bootstrap()->run();
41 | $actual = ob_get_contents();
42 | ob_end_clean();
43 |
44 | $this->assertSame('Dummy', $actual);
45 | }
46 |
47 | public function tearDown()
48 | {
49 | parent::setUp();
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/tests/P025Test.php:
--------------------------------------------------------------------------------
1 | [
30 | 'directory' => realpath(dirname(__FILE__)),
31 | 'library' => [
32 | 'directory' => '/tmp',
33 | 'namespace' => 'Foo, Bar',
34 | ],
35 | ],
36 | ];
37 |
38 | $app = new Application($config);
39 | Loader::getInstance()->registerLocalNamespace('Dummy');
40 | $loader = Loader::getInstance();
41 | $this->assertSame('/tmp', $loader->getLibraryPath());
42 | $this->assertSame('/php/global/dir', $loader->getLibraryPath(true));
43 | $this->assertTrue(Loader::getInstance()->isLocalName('Bar_Name'));
44 | }
45 |
46 | public function tearDown()
47 | {
48 | parent::tearDown();
49 |
50 | YAF_G('yaf.library', YAF_G('bak_library'));
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/tests/P069Test.php:
--------------------------------------------------------------------------------
1 | [
29 | 'directory' => YAF_TEST_APPLICATION_PATH,
30 | ],
31 | ];
32 |
33 | file_put_contents(YAF_TEST_APPLICATION_PATH . "/controllers/Index.php", << tail" . PHP_EOL);
44 |
45 | ob_start();
46 | $app = new Application($config);
47 | $app->run();
48 | $acutal = ob_get_contents();
49 | ob_end_clean();
50 |
51 | $this->assertTrue(stripos($acutal, 'head') !== false && stripos($acutal, 'tail') !== false);
52 | }
53 |
54 | public function tearDown()
55 | {
56 | parent::setUp();
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/tests/P061Test.php:
--------------------------------------------------------------------------------
1 | [
29 | 'directory' => YAF_TEST_APPLICATION_PATH,
30 | ],
31 | ];
32 |
33 | file_put_contents(YAF_TEST_APPLICATION_PATH . '/controllers/Index.php', file_get_contents(__DIR__ . '/common/061Test_1.inc'));
34 | file_put_contents(YAF_TEST_APPLICATION_PATH . '/controllers/Dummy.php', file_get_contents(__DIR__ . '/common/061Test_2.inc'));
35 | file_put_contents(YAF_TEST_APPLICATION_PATH . '/views/index/index.phtml', '');
36 | file_put_contents(YAF_TEST_APPLICATION_PATH . '/views/index/dummy.phtml', 'Dummy');
37 |
38 | ob_start();
39 | $app = new Application($config);
40 | $response = $app->run();
41 | $actual = ob_get_contents();
42 | ob_end_clean();
43 |
44 | $this->assertSame('Dummy', $actual);
45 | }
46 |
47 | public function tearDown()
48 | {
49 | parent::setUp();
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/tests/P065Test.php:
--------------------------------------------------------------------------------
1 | addConfig(
30 | [
31 | [
32 | 'type' => 'regex',
33 | 'match' => "#^/ap/([^/]*)/*#i",
34 | 'route' => [
35 | [
36 | 'action' => 'ap',
37 | ],
38 | ],
39 | ]
40 | ]
41 | )->route($request);
42 |
43 | $this->assertSame(0, $router->getCurrentRoute());
44 | $this->assertNull($request->getActionName());
45 |
46 | $router->addRoute('regex', new Regex("#^/ap/([^/]*)/*#i", ['action' => 'ap']))->route($request);
47 |
48 | $this->assertSame('regex', $router->getCurrentRoute());
49 | $this->assertSame('ap', $request->getActionName());
50 | }
51 |
52 | public function tearDown()
53 | {
54 | parent::setUp();
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/tests/P039Test.php:
--------------------------------------------------------------------------------
1 | markTestSkipped('syntax error test');
18 |
19 | require_once __DIR__ . '/common/build.inc';
20 | startup();
21 | }
22 |
23 | /**
24 | * @throws Exception
25 | */
26 | public function test()
27 | {
28 | $view = new Simple(DIR_ROOT);
29 | $view->assign('name', 'laruence');
30 | $tpl = YAF_TEST_APPLICATION_PATH . '/tpls/foo.phtml';
31 | $tpl2 = YAF_TEST_APPLICATION_PATH . '/tpls/foo2.phtml';
32 |
33 | file_put_contents($tpl, <<render(\$tpl);
36 | ?>
37 | HTML
38 | );
39 |
40 | file_put_contents($tpl2, <<
45 | HTML
46 | );
47 |
48 | $exception = false;
49 | try {
50 | echo $view->render($tpl, ['tpl' => $tpl2]);
51 | } catch (Error $e) {
52 | $exception = true;
53 | $this->assertSame("syntax error, unexpected '}'", $e->getMessage());
54 | }
55 |
56 | $this->assertTrue($exception);
57 | }
58 |
59 | public function tearDown()
60 | {
61 | parent::setUp();
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/tests/P059Test.php:
--------------------------------------------------------------------------------
1 | [
28 | 'directory' => YAF_TEST_APPLICATION_PATH,
29 | ],
30 | ];
31 |
32 | file_put_contents(YAF_TEST_APPLICATION_PATH . '/Bootstrap.php', file_get_contents(__DIR__ . '/common/059Test_1.inc'));
33 | file_put_contents(YAF_TEST_APPLICATION_PATH . '/controllers/Index.php', file_get_contents(__DIR__ . '/common/059Test_2.inc'));
34 | file_put_contents(YAF_TEST_APPLICATION_PATH . '/views/index/index.phtml', "display('index/sub.phtml', array('content' => 'dummy'));?>");
35 | file_put_contents(YAF_TEST_APPLICATION_PATH . '/views/index/sub.phtml', "eval('foobar'); ?>");
36 |
37 | $app = new Application($config);
38 | ob_start();
39 | $response = $app->bootstrap()->run();
40 | $actual = ob_get_contents();
41 | ob_end_clean();
42 |
43 | $this->assertTrue(stripos($actual, 'dummyfoobar') !== false);
44 | }
45 |
46 | public function tearDown()
47 | {
48 | parent::setUp();
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/tests/P073Test.php:
--------------------------------------------------------------------------------
1 | 'product',
28 | ], []);
29 | $router->addRoute('rewrite', $route);
30 |
31 | $this->assertSame('/product/foo/bar/tmpkey1/tmpval1/?tkey1=tval1&tkey2=tval2', $router->getRoute('rewrite')->assemble(
32 | [
33 | ':name' => 'foo',
34 | ':id' => 'bar',
35 | ':tmpkey1' => 'tmpval1'
36 | ],
37 | [
38 | 'tkey1' => 'tval1',
39 | 'tkey2' => 'tval2'
40 | ]
41 | ));
42 |
43 | $this->assertSame('/product/foo/1/tmpkey1/tmpval1/?tkey1=tval1&tkey2=22222', $router->getRoute('rewrite')->assemble(
44 | [
45 | ':name' => 'foo',
46 | ':id' => 1,
47 | ':tmpkey1' => 'tmpval1'
48 | ],
49 | [
50 | 'tkey1' => 'tval1',
51 | 'tkey2' => 22222
52 | ]
53 | ));
54 | }
55 |
56 | public function tearDown()
57 | {
58 | parent::setUp();
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/tests/P077Test.php:
--------------------------------------------------------------------------------
1 | addRoute('static', $route);
29 |
30 | $this->assertSame('/yafmodule/yafcontroller/yafaction?tkey1=tval1&tkey2=tval2', $router->getRoute('static')->assemble(
31 | array(
32 | ':a' => 'yafaction',
33 | 'tkey' => 'tval',
34 | ':c' => 'yafcontroller',
35 | ':m' => 'yafmodule'
36 | ),
37 | array(
38 | 'tkey1' => 'tval1',
39 | 'tkey2' => 'tval2'
40 | )
41 | )
42 | );
43 |
44 | $this->assertSame('/yafmodule/yafcontroller/yafaction', $router->getRoute('static')->assemble(
45 | array(
46 | ':a' => 'yafaction',
47 | 'tkey' => 'tval',
48 | ':c' => 'yafcontroller',
49 | ':m' => 'yafmodule'
50 | ),
51 | array(
52 | 1 => 2,
53 | array(),
54 | )
55 | ));
56 | }
57 |
58 | public function tearDown()
59 | {
60 | parent::setUp();
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/tests/P067Test.php:
--------------------------------------------------------------------------------
1 | [
30 | 'directory' => YAF_TEST_APPLICATION_PATH,
31 | ],
32 | ];
33 |
34 | file_put_contents(YAF_TEST_APPLICATION_PATH . '/controllers/Index.php', file_get_contents(__DIR__ . '/common/067Test_1.inc'));
35 | file_put_contents(YAF_TEST_APPLICATION_PATH . '/actions/sub.php', file_get_contents(__DIR__ . '/common/067Test_2.inc'));
36 | file_put_contents(YAF_TEST_APPLICATION_PATH . '/views/index/index.phtml', 'indexAction' . PHP_EOL);
37 | file_put_contents(YAF_TEST_APPLICATION_PATH . '/views/index/sub.phtml', 'subAction' . PHP_EOL);
38 |
39 | $app = new Application($config);
40 |
41 | $request = new Simple();
42 | $app->getDispatcher()->dispatch($request);
43 |
44 | $new_request = new Simple();
45 | $new_request->setActionName('sub');
46 | $app->getDispatcher()->dispatch($new_request);
47 |
48 | $this->assertSame('ok', 'ok');
49 | }
50 |
51 | public function tearDown()
52 | {
53 | parent::setUp();
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/tests/P005Test.php:
--------------------------------------------------------------------------------
1 | appendBody($body);
31 | $response->prependBody($string);
32 | $response->appendBody('kfjdaksljfklajdsfkljasdkljfkjasdf');
33 |
34 | $body = $response->getBody();
35 | $this->assertSame('content', Response_Abstract::DEFAULT_BODY);
36 | $this->assertSame([
37 | 'content' => 'laruenceifjakdsljfklasdjfkljasdkljfkljadsfkfjdaksljfklajdsfkljasdkljfkjasdf'
38 | ], $response->getBody(null));
39 | $this->assertSame(
40 | 'laruenceifjakdsljfklasdjfkljasdkljfkljadsfkfjdaksljfklajdsfkljasdkljfkjasdf',
41 | $response->getBody(Http::DEFAULT_BODY)
42 | );
43 | $this->assertEquals('laruenceifjakdsljfklasdjfkljasdkljfkljadsfkfjdaksljfklajdsfkljasdkljfkjasdf', $response);
44 |
45 | ob_start();
46 | $response->response();
47 | $response = ob_get_contents();
48 | ob_end_clean();
49 | $this->assertEquals('laruenceifjakdsljfklasdjfkljasdkljfkljadsfkfjdaksljfklajdsfkljasdkljfkjasdf', $response);
50 | }
51 |
52 | public function tearDown()
53 | {
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/tests/P027Test.php:
--------------------------------------------------------------------------------
1 | [
33 | 'directory' => realpath(dirname(__FILE__)),
34 | 'dispatcher' => [
35 | 'catchException' => 0,
36 | 'throwException' => 0,
37 | ],
38 | ],
39 | ];
40 |
41 | $app = new Application($config);
42 | $this->assertSame('product', $app->environ());
43 | $this->assertSame(2, count($app->getConfig()->application));
44 |
45 | @$app->execute(123);
46 | $this->assertSame('Yaf_Application::execute must be a valid callback', error_get_last()['message']);
47 | }
48 |
49 | public function tearDown()
50 | {
51 | parent::tearDown();
52 |
53 | YAF_G('yaf.use_spl_autoload', YAF_G('bak_use_spl_autoload'));
54 | YAF_G('yaf.library', YAF_G('bak_library'));
55 | YAF_G('yaf.environ', YAF_G('bak_environ'));
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/tests/P042Test.php:
--------------------------------------------------------------------------------
1 | [
42 | 'directory' => realpath(dirname(__FILE__)),
43 | 'dispatcher' => [
44 | 'catchException' => 0,
45 | 'throwException' => 1,
46 | ],
47 | 'modules' => 'module',
48 | ],
49 | ];
50 |
51 |
52 | $app = new Application($config);
53 | $request = new Http('/module/controller/index');
54 |
55 | $exception = false;
56 | try {
57 | $app->getDispatcher()->returnResponse(false)->dispatch($request);
58 | } catch (\Exception $e) {
59 | $exception = true;
60 | $this->assertSame('exception', $e->getMessage());
61 | }
62 | $this->assertTrue($exception);
63 | }
64 |
65 | public function tearDown()
66 | {
67 | parent::setUp();
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/tests/P016Test.php:
--------------------------------------------------------------------------------
1 | age = $age;
32 | unset($age);
33 |
34 | unset($session);
35 | $session2 = @Session::getInstance();
36 | $session2["company"] = "Baidu";
37 | $this->assertTrue(isset($session2->age));
38 | $this->assertTrue($session2->has("name"));
39 | $this->assertSame(3, count($session2));
40 |
41 | ob_start();
42 | foreach ($session2 as $key => $value) {
43 | echo $key , "=>", $value, "\n";
44 | }
45 | $actual = ob_get_contents();
46 | ob_end_clean();
47 |
48 | $expected = <<
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 | # 目录
23 |
24 | + [1 关于Yaf-PHP](#1-关于yaf-php)
25 | + [1.1 简介](#11-简介)
26 | + [1.2 依赖](#12-依赖)
27 | + [1.3 安装](#13-安装)
28 | + [1.4 快速使用](#14-快速使用)
29 | - [1.4.1 PhpStorm引入](#141-在phpstorm引入)
30 | - [1.4.2 NetBeans引入](#142-在netbeans引入)
31 | + [1.5 最终效果图](#15-最终效果图)
32 | + [2 相关链接](#2-相关链接)
33 | + [3 待解决问题](#3待解决问题)
34 |
35 | # 1. 关于Yaf-PHP
36 |
37 | ## 1.1 简介
38 |
39 | ```Yaf-PHP```采用原生PHP对Yaf源码进行了逻辑重写,最大程度还原其相关实现逻辑.
40 |
41 | 由于采用了原生PHP重写,可达到抹平阅读能力,降低阅读成本的目的.在平常开发时,也可以作为IDE Helper进行引入,加快开发效率.
42 |
43 | ## 1.2 依赖
44 |
45 | | 依赖项 | 版本 | 说明 |
46 | |--------|--------|--------|
47 | | PHP | 7.0+ | IDE运行的PHP环境,并非服务运行环境 |
48 |
49 | ## 1.3 安装
50 |
51 |
52 | ```bash
53 | > git clone https://github.com/yinggaozhen/yaf-php.git
54 | ```
55 |
56 | ## 1.4 快速使用
57 |
58 | ### 1.4.1 在PhpStorm引入
59 |
60 | 两种实现方法
61 |
62 | ~~~
63 | 左侧导航栏 `External Libraries` -> `Configure PHP Include Path` -> 添加`Yaf-PHP`文件路径 -> `apply`
64 | ~~~
65 |
66 | ~~~
67 | 菜单 `File` -> `Setting` -> `Languages & Frameworks` -> `PHP` -> 添加`Yaf-PHP`文件路径 -> `apply`
68 | ~~~
69 |
70 | ### 1.4.2 在NetBeans引入
71 |
72 | ~~~
73 | 右击你的项目 -> `Properties` -> `PHP Include Path` -> `Add Folder..` -> 添加`Yaf-PHP`文件路径 -> `open`
74 | ~~~
75 |
76 | ## 1.5 最终效果图
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 | # 2 相关链接
87 |
88 | - [Yaf官方文档](http://www.laruence.com/manual/)
89 | - [Yaf源码](https://github.com/laruence/yaf)
90 | - [Yaf Doc](https://github.com/elad-yosifon/php-yaf-doc)
91 |
92 | # 3.待解决问题
93 |
94 | - [ ] 接入travis CI/codecov/lint,内容包含单元测试/测试覆盖率/代码规范校验
95 | - [x] 项目中TODO List清理
96 | - [x] 测试用例完善
97 | - [x] README文档完善
98 | - [x] 加载方式同时支持PSR4和PSR0
99 | - [x] 代码注释完善,包括函数入参出参参数说明,以及每个函数作用说明
100 |
--------------------------------------------------------------------------------
/tests/P007Test.php:
--------------------------------------------------------------------------------
1 | [
25 | 'name' => 'value',
26 | 'dummy' => 'foo',
27 | ],
28 | 'section2' => "laruence",
29 | ];
30 |
31 | $config1 = new Simple($config, 'section2');
32 | $this->assertSame([
33 | 'section1' => [
34 | 'name' => 'value',
35 | 'dummy' => 'foo',
36 | ],
37 | 'section2' => "laruence",
38 | ], $config1->_config);
39 |
40 | //---------------------------------------
41 |
42 | $config2 = new Simple($config, 'section1');
43 | $this->assertTrue($config2->readonly());
44 | $config2->new = 'value';
45 | $this->assertFalse(isset($config->new));
46 |
47 | //---------------------------------------
48 |
49 | $config3 = new Simple($config);
50 | unset($config);
51 | $this->assertTrue(isset($config3['section2']));
52 | $config3->new = "value";
53 | $this->assertFalse($config3->readonly());
54 |
55 | ob_start();
56 | foreach ($config3 as $key => $val) {
57 | print_r($key);
58 | print_r("=>");
59 | print_r($val);
60 | print_r(PHP_EOL);
61 | }
62 | $buf = ob_get_contents();
63 | ob_end_clean();
64 | $output = <<