Skip to content

Commit

Permalink
Add test suite back into Proem codebase.
Browse files Browse the repository at this point in the history
  • Loading branch information
trq committed May 19, 2012
1 parent 8261dcd commit 080877f
Show file tree
Hide file tree
Showing 30 changed files with 2,056 additions and 0 deletions.
11 changes: 11 additions & 0 deletions tests/bootstrap.php
@@ -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();
83 changes: 83 additions & 0 deletions tests/lib/Proem/Tests/AutoloaderTest.php
@@ -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');
}
}
19 changes: 19 additions & 0 deletions tests/lib/Proem/Tests/Ext/Fixtures/MyApp/Module/Foo.php
@@ -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';
}
}
64 changes: 64 additions & 0 deletions tests/lib/Proem/Tests/ExtTest.php
@@ -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();
}

}
75 changes: 75 additions & 0 deletions tests/lib/Proem/Tests/FilterTest.php
@@ -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);
}

}
30 changes: 30 additions & 0 deletions tests/lib/Proem/Tests/Fixtures/Namespaced/Bar.php
@@ -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
{}
35 changes: 35 additions & 0 deletions tests/lib/Proem/Tests/Fixtures/Namespaced/Boo.php
@@ -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';
}
}
30 changes: 30 additions & 0 deletions tests/lib/Proem/Tests/Fixtures/Namespaced/Foo.php
@@ -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
{}
28 changes: 28 additions & 0 deletions tests/lib/Proem/Tests/Fixtures/Pear/Bar.php
@@ -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
{}

0 comments on commit 080877f

Please sign in to comment.