Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test suite back into Proem codebase.
- Loading branch information
Showing
30 changed files
with
2,056 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
require_once 'lib/Proem/Autoloader.php'; | ||
|
||
use Proem\Autoloader; | ||
|
||
$loader = new AutoLoader(); | ||
$loader->registerNamespaces([ | ||
'Proem\Tests' => 'tests/lib', | ||
'Proem' => ['tests/lib/Proem/Tests/Fixtures', 'lib'] | ||
])->register(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<?php | ||
|
||
/** | ||
* The MIT License | ||
* | ||
* Copyright (c) 2010 - 2012 Tony R Quilkey <trq@proemframework.org> | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
|
||
namespace Proem\Tests; | ||
|
||
use Proem\Autoloader; | ||
use Namespaced; | ||
|
||
class AutoloaderTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @dataProvider getData | ||
*/ | ||
public function testLoad($className, $testClassName, $message) | ||
{ | ||
(new AutoLoader()) | ||
->registerNamespace('Namespaced', __DIR__ . '/Fixtures') | ||
->registerPearPrefix('Pear_', __DIR__ . '/Fixtures') | ||
->load($testClassName); | ||
|
||
$this->assertTrue(class_exists($className), $message); | ||
} | ||
|
||
/** | ||
* @dataProvider getData | ||
*/ | ||
public function testRegister($className, $testClassName, $message) | ||
{ | ||
(new AutoLoader()) | ||
->registerNamespace('Namespaced', __DIR__ . '/Fixtures') | ||
->registerPearPrefix('Pear_', __DIR__ . '/Fixtures') | ||
->register(); | ||
|
||
$this->assertTrue(class_exists($className), $message); | ||
} | ||
|
||
public function getData() | ||
{ | ||
return [ | ||
['\Namespaced\Foo', 'Namespaced\Foo', 'Including Namespaced\Foo class'], | ||
['\Pear_Foo', 'Pear_Foo', 'Including Pear_Foo class'], | ||
['\Namespaced\Bar', '\Namespaced\Bar', 'Including \Namespaced\Bar class'], | ||
['\Pear_Bar', '\Pear_Bar', 'Including \Pear_Bar class'] | ||
]; | ||
} | ||
|
||
public function testOverload() | ||
{ | ||
(new AutoLoader()) | ||
->registerNamespace('Namespaced', [ | ||
__DIR__ . '/Override', | ||
__DIR__ . '/Fixtures' | ||
]) | ||
->load('Namespaced\Boo'); | ||
|
||
$boo = new Namespaced\Boo; | ||
|
||
$this->assertEquals($boo->getMessage(), 'override', 'Including overriden Proem\Boo'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace MyApp\Module; | ||
|
||
use \Proem\Service\Manager\Template as Manager; | ||
|
||
class Foo extends \Proem\Ext\Module\Generic | ||
{ | ||
public function init(Manager $assets, $env = null) { | ||
$assets->get('events')->attach([ | ||
'name' => 'pre.in.router', | ||
'callback' => [$this, 'loadRoutes'] | ||
]); | ||
} | ||
|
||
public function loadRoutes($e) { | ||
echo 'Foo Module Loaded'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
|
||
/** | ||
* The MIT License | ||
* | ||
* Copyright (c) 2010 - 2012 Tony R Quilkey <trq@proemframework.org> | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
|
||
namespace Proem\Tests; | ||
|
||
use Proem\Autoloader, | ||
MyApp\Module\Foo; | ||
|
||
class ExtTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function setUp() | ||
{ | ||
(new Autoloader) | ||
->registerNamespace('MyApp', dirname(__FILE__) . '/Ext/Fixtures') | ||
->register(); | ||
} | ||
|
||
public function testFooModuleLoads() | ||
{ | ||
$this->expectOutputString('Foo Module Loaded<h3>404 - Page Not Found</h3>'); | ||
|
||
(new \Proem\Proem) | ||
->attachModule(new Foo) | ||
->init(); | ||
} | ||
|
||
/** | ||
* The Foo module listens for the pre.in.route signal event, | ||
* Loading it now (at post.in.route) will never give it a chance | ||
* to set itself up. | ||
*/ | ||
public function testFooModuleWontLoadWhenAttachedTooLate() | ||
{ | ||
$this->expectOutputString('<h3>404 - Page Not Found</h3>'); | ||
|
||
(new \Proem\Proem) | ||
->attachModule(new Foo, 'post.in.route') | ||
->init(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php | ||
|
||
/** | ||
* The MIT License | ||
* | ||
* Copyright (c) 2010 - 2012 Tony R Quilkey <trq@proemframework.org> | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
|
||
namespace Proem\Tests; | ||
|
||
use Proem\Filter\Manager\Standard as FilterManager, | ||
Proem\Service\Manager\Standard as ServiceManager; | ||
|
||
class FilterTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
private $request; | ||
private $response; | ||
private $route; | ||
private $dispatch; | ||
|
||
public function setUp() { | ||
$this->response = $this->getMockForAbstractClass('Proem\Filter\Event\Generic'); | ||
$this->request = $this->getMockForAbstractClass('Proem\Filter\Event\Generic'); | ||
$this->route = $this->getMockForAbstractClass('Proem\Filter\Event\Generic'); | ||
$this->dispatch = $this->getMockForAbstractClass('Proem\Filter\Event\Generic'); | ||
} | ||
public function testCanInstantiate() | ||
{ | ||
$this->assertInstanceOf('Proem\Filter\Manager\Standard', new FilterManager(new ServiceManager)); | ||
} | ||
|
||
public function testFilterManagerRun() { | ||
$r = new \StdClass; | ||
$r->out = ''; | ||
$this->response->expects($this->once())->method('inBound')->will($this->returnCallback(function() use ($r) {$r->out .= "response in, ";})); | ||
$this->response->expects($this->once())->method('outBound')->will($this->returnCallback(function() use ($r) {$r->out .= "response out";})); | ||
|
||
$this->request->expects($this->once())->method('inBound')->will($this->returnCallback(function() use ($r) {$r->out .= "request in, ";})); | ||
$this->request->expects($this->once())->method('outBound')->will($this->returnCallback(function() use ($r) {$r->out .= "request out, ";})); | ||
|
||
$this->route->expects($this->once())->method('inBound')->will($this->returnCallback(function() use ($r) {$r->out .= "route in, ";})); | ||
$this->route->expects($this->once())->method('outBound')->will($this->returnCallback(function() use ($r) {$r->out .= "route out, ";})); | ||
|
||
$this->dispatch->expects($this->once())->method('inBound')->will($this->returnCallback(function() use ($r) {$r->out .= "dispatch in, ";})); | ||
$this->dispatch->expects($this->once())->method('outBound')->will($this->returnCallback(function() use ($r) {$r->out .= "dispatch out, ";})); | ||
|
||
(new FilterManager(new ServiceManager)) | ||
->attachEvent($this->response, FilterManager::RESPONSE_EVENT_PRIORITY) | ||
->attachEvent($this->request, FilterManager::REQUEST_EVENT_PRIORITY) | ||
->attachEvent($this->route, FilterManager::ROUTE_EVENT_PRIORITY) | ||
->attachEvent($this->dispatch, FilterManager::DISPATCH_EVENT_PRIORITY) | ||
->init(); | ||
|
||
$this->assertEquals('response in, request in, route in, dispatch in, dispatch out, route out, request out, response out', $r->out); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
/** | ||
* The MIT License | ||
* | ||
* Copyright (c) 2010 - 2012 Tony R Quilkey <trq@proemframework.org> | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
|
||
namespace Namespaced; | ||
|
||
class Bar | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
/** | ||
* The MIT License | ||
* | ||
* Copyright (c) 2010 - 2012 Tony R Quilkey <trq@proemframework.org> | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
|
||
namespace Namespaced; | ||
|
||
class Boo | ||
{ | ||
public function getMessage() | ||
{ | ||
return 'original'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
/** | ||
* The MIT License | ||
* | ||
* Copyright (c) 2010 - 2012 Tony R Quilkey <trq@proemframework.org> | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
|
||
namespace Namespaced; | ||
|
||
class Foo | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
/** | ||
* The MIT License | ||
* | ||
* Copyright (c) 2010 - 2012 Tony R Quilkey <trq@proemframework.org> | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
|
||
class Pear_Bar | ||
{} |
Oops, something went wrong.