Skip to content

Commit

Permalink
Merge pull request zendframework#47 from Hounddog/feature/testing
Browse files Browse the repository at this point in the history
Feature/testing
  • Loading branch information
Hounddog committed Oct 30, 2012
2 parents 6507116 + 0307bf7 commit 31a067a
Show file tree
Hide file tree
Showing 13 changed files with 178 additions and 60 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@
[submodule "vendor/ScnSocialAuth"]
path = vendor/ScnSocialAuth
url = https://github.com/Hounddog/ScnSocialAuth.git
[submodule "vendor/EdpGithub"]
path = vendor/EdpGithub
url = https://github.com/EvanDotPro/EdpGithub
12 changes: 12 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
language: php
php:
- "5.3"

before_script:
- git submodule update --init --recursive

script:
- phpunit

notifications:
irc: "irc.freenode.org#zftalk.dev.modules"
51 changes: 51 additions & 0 deletions Bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php
namespace EdpGithubTest;

use Zend\Loader\AutoloaderFactory;
use Zend\Mvc\Service\ServiceManagerConfig;
use Zend\ServiceManager\ServiceManager;
use Zend\Stdlib\ArrayUtils;
use RuntimeException;

error_reporting(E_ALL | E_STRICT);
chdir(__DIR__);

class Bootstrap
{
protected static $serviceManager;

public static function init()
{
// Load the user-defined test configuration file, if it exists; otherwise, load
$config = include __DIR__ . '/config/application.config.php';

static::initAutoloader();

$serviceManager = new ServiceManager(new ServiceManagerConfig());
$serviceManager->setService('ApplicationConfig', $config);
$serviceManager->get('ModuleManager')->loadModules();
static::$serviceManager = $serviceManager;
}

public static function getServiceManager()
{
return static::$serviceManager;
}

protected static function initAutoloader()
{
$loader = include __DIR__ . '/init_autoloader.php';

AutoloaderFactory::factory(array(
'Zend\Loader\StandardAutoloader' => array(
'autoregister_zf' => true,
'namespaces' => array(
'ApplicationTest' => __DIR__ . '/module/Application/test/ApplicationTest',
'UserTest' => __DIR__ . '/module/User/test/UserTest',
),
),
));
}
}

Bootstrap::init();
1 change: 0 additions & 1 deletion config/application.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
'ScnSocialAuth' => '../moduledev/ScnSocialAuth',
'./module',
'./vendor',
'../moduledev',
),
),
);
2 changes: 1 addition & 1 deletion module/Application/src/Application/Service/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function getAllRepository($type)
if(!isset($this->repository[$type])) {
$client = $this->api;

$this->repositories[$type] = $client->api('current_user')->repos($type);
$this->repositories[$type] = $client->api('current_user')->repos();
}
return $this->repositories[$type];
}
Expand Down
6 changes: 2 additions & 4 deletions module/Application/src/Application/View/Helper/UserWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,13 @@ class UserWidget extends AbstractHelper
*/
public function __invoke()
{

$vm = new ViewModel();
$vm->setTemplate('user/user-widget.phtml');

return $this->getView()->render($vm);
}


/**
* @param string $viewTemplate
* @return ZfcUserLoginWidget
Expand All @@ -37,5 +36,4 @@ public function setViewTemplate($viewTemplate)
$this->viewTemplate = $viewTemplate;
return $this;
}

}
34 changes: 18 additions & 16 deletions module/Application/test/ApplicationTest/Service/RepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,33 @@

class RepositoryTest extends PHPUnit_Framework_TestCase
{
public function setUp()
{
// your code here
}

public function tearDown()
{
// your code here
}

public function testGetAllRepositories()
{
$api = $this->getMock('EdpGithub\ApiClient\ApiClient');
$repo = $this->getMock('EdpGithub\ApiClient\ApiFactory\Service\Repo');
$repo = $this->getMock(
'EdpGithub\Collection\RepositoryCollection',
array(),
array($this->getMock('EdpGithub\Http\Client'), 'somePath')
);

$currentUser = $this->getMock('EdpGithub\Api\CurrentUser');
$currentUser->expects($this->once())
->method('repos')
->will($this->returnValue($repo));

$api = $this->getMock('EdpGithub\Client');

$api->expects($this->once())
->method('getService')
->with($this->equalTo('Repo'))
->will($this->returnValue('test'));
->method('api')
->with($this->equalTo('current_user'))
->will($this->returnValue($currentUser));


$service = new Repository();
$service->setApi($api);

$service->getAllRepository('member');

$result = $service->getAllRepository('member');

$this->assertInstanceOf('edpGithub\Collection\RepositoryCollection', $result);
}
}
34 changes: 16 additions & 18 deletions module/Application/test/Bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
namespace ApplicationTest;
namespace EdpGithubTest;

use Zend\Loader\AutoloaderFactory;
use Zend\Mvc\Service\ServiceManagerConfig;
Expand Down Expand Up @@ -71,27 +71,25 @@ protected static function initAutoloader()

if (is_readable($vendorPath . '/autoload.php')) {
$loader = include $vendorPath . '/autoload.php';
}
} else {
$zf2Path = getenv('ZF2_PATH') ?: (defined('ZF2_PATH') ? ZF2_PATH : (is_dir($vendorPath . '/ZF2/library') ? $vendorPath . '/ZF2/library' : false));

$zf2Path = getenv('ZF2_PATH') ?: (defined('ZF2_PATH') ? ZF2_PATH : (is_dir($vendorPath . '/ZF2/library') ? $vendorPath . '/ZF2/library' : false));
if (!$zf2Path) {
throw new RuntimeException('Unable to load ZF2. Run `php composer.phar install` or define a ZF2_PATH environment variable.');
}

include $zf2Path . '/Zend/Loader/AutoloaderFactory.php';

if (!$zf2Path) {
throw new RuntimeException('Unable to load ZF2. Run `php composer.phar install` or define a ZF2_PATH environment variable.');
}

if (isset($loader)) {
$loader->add('Zend', $zf2Path . '/Zend');
} else {
include $zf2Path . '/Zend/Loader/AutoloaderFactory.php';
AutoloaderFactory::factory(array(
'Zend\Loader\StandardAutoloader' => array(
'autoregister_zf' => true,
'namespaces' => array(
__NAMESPACE__ => __DIR__ . '/' . __NAMESPACE__,
),
AutoloaderFactory::factory(array(
'Zend\Loader\StandardAutoloader' => array(
'autoregister_zf' => true,
'namespaces' => array(
__NAMESPACE__ => __DIR__ . '/' . __NAMESPACE__,
),
));
}
),
));
}

protected static function findParentPath($path)
Expand All @@ -107,4 +105,4 @@ protected static function findParentPath($path)
}
}

Bootstrap::init();
Bootstrap::init();
36 changes: 29 additions & 7 deletions module/Application/test/phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,29 @@
<phpunit bootstrap="./Bootstrap.php" colors="true">
<testsuites>
<testsuite name="Application Module Tests">
<directory>./ApplicationTest</directory>
</testsuite>
</testsuites>
</phpunit>
<?xml version="1.0"?>
<!-- works fine with PHPUnit-3.6.10 -->
<phpunit
bootstrap="./Bootstrap.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
verbose="true"
stopOnFailure="false"
processIsolation="false"
backupGlobals="false"
syntaxCheck="true"
>
<testsuite name="EdpGithub Module Tests">
<directory>./ApplicationTest</directory>
</testsuite>
<filter>
<whitelist addUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src</directory>
</whitelist>
</filter>
<logging>
<log
type="coverage-clover"
target="./clover.xml"
/>
</logging>
</phpunit>
8 changes: 5 additions & 3 deletions module/User/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ public function bootstrap(ModuleManager $moduleManager, ApplicationInterface $ap
$em->attach('EdpGithub\Client', 'api', function($e) use ($sm) {
$hybridAuth = $sm->get('HybridAuth');
$adapter = $hybridAuth->getAdapter('github');
$token = $adapter->getAccessToken();

$client = $e->getTarget();
$client->authenticate('url_token', $token['access_token']);
if($adapter->isUserConnected()) {
$token = $adapter->getAccessToken();
$client = $e->getTarget();
$client->authenticate('url_token', $token['access_token']);
}
} );
}

Expand Down
18 changes: 9 additions & 9 deletions module/User/view/zfc-user/user/index.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,14 @@
<div class="span5 module-author">
<div class="row-fluid">
<div class="span2">
<?php $owner = $module->getOwner(); ?>
<img src="<?=$owner['avatar_url']?> " />
<?php $owner = $module->owner; ?>
<img src="<?=$owner->avatar_url?> " />
</div>
<div class="span10">
<strong><?=$owner['login']?></strong>
<strong><?=$owner->login?></strong>
<p>
<span class="author-label">Github:</span>
<a href="<?=$module->getUrl()?>"><?=$module->getName()?></a><br />
<a href="<?=$module->url?>"><?=$module->name?></a><br />
<!--
<span class="author-label">Blog:</span> <a>placeholder</a><br />
<span class="author-label">Modules:</span> <a>5</a><br /><br />
Expand All @@ -174,13 +174,13 @@
</div>
</div>
<div class="span5">
<strong><?=$module->getName()?></strong>
<strong><?=$module->name?></strong>
<p>
<!--<span class="author-label">Version:</span> 1.2.1<br />-->
<span class="author-label">Created:</span>
<?php
$date = new DateTime($module->getCreatedAt());
echo $date->format('Y-m-d');
//$date = new DateTime($module->getCreatedAt());
//echo $date->format('Y-m-d');
?><br />
<!--<span class="author-label">Edited:</span> <a>15 days ago</a><br />
<span class="author-label">Tags:</span>
Expand All @@ -193,7 +193,7 @@
<div class="span1">
<br />
<form action="<?=$this->url('module/add_module')?>" method="post">
<input type="hidden" name="repository" value="<?=$module->getHtmlUrl()?>" />
<input type="hidden" name="repository" value="<?=$module->html_url?>" />
<input type="submit" class="btn btn-success"/>
</form>
</div>
Expand All @@ -205,7 +205,7 @@
<div class="span12">
<strong>Description</strong>
<p>
<?=$module->getDescription()?>
<?=$module->description?>
</p>
</div>
<div style="clear: both;"></div>
Expand Down
31 changes: 31 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0"?>
<!-- works fine with PHPUnit-3.6.10 -->
<phpunit
bootstrap="./Bootstrap.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
verbose="true"
stopOnFailure="false"
processIsolation="false"
backupGlobals="false"
syntaxCheck="true"
>
<testsuite name="Test all modules">
<directory>./module/Application/test/ApplicationTest</directory>
<directory>./module/User/test/UserTest</directory>
</testsuite>
<filter>
<whitelist addUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./module/Application/src</directory>
<directory suffix=".php">./module/User/src</directory>
</whitelist>
</filter>
<logging>
<log
type="coverage-clover"
target="./clover.xml"
/>
</logging>
</phpunit>
2 changes: 1 addition & 1 deletion vendor/EdpGithub
Submodule EdpGithub updated 68 files
+21 −0 .travis.yml
+0 −298 ApiClient/ApiClient.php
+0 −20 ApiClient/ApiFactory.php
+0 −414 ApiClient/Model/Repo.php
+0 −320 ApiClient/Model/User.php
+0 −34 ApiClient/Service/AbstractService.php
+0 −8 ApiClient/Service/Exception/DomainException.php
+0 −7 ApiClient/Service/Exception/ExceptionInterface.php
+0 −57 ApiClient/Service/Repo.php
+2 −62 Module.php
+46 −0 README.md
+15 −96 config/module.config.php
+33 −0 coverage-checker.php
+29 −0 phpunit.xml
+57 −0 src/EdpGithub/Api/AbstractApi.php
+8 −0 src/EdpGithub/Api/ApiInterface.php
+36 −0 src/EdpGithub/Api/CurrentUser.php
+7 −0 src/EdpGithub/Api/Exception/ExceptionInterface.php
+8 −0 src/EdpGithub/Api/Exception/InvalidArgumentException.php
+8 −0 src/EdpGithub/Api/Gist.php
+8 −0 src/EdpGithub/Api/GitData.php
+8 −0 src/EdpGithub/Api/Issue.php
+8 −0 src/EdpGithub/Api/Markdown.php
+8 −0 src/EdpGithub/Api/Organization.php
+8 −0 src/EdpGithub/Api/PullRequest.php
+25 −0 src/EdpGithub/Api/Repos.php
+19 −0 src/EdpGithub/Api/User.php
+0 −248 src/EdpGithub/ApiClient/ApiClient.php
+0 −34 src/EdpGithub/ApiClient/Service/AbstractService.php
+0 −19 src/EdpGithub/ApiClient/Service/Repo.php
+0 −24 src/EdpGithub/ApiClient/Service/User.php
+130 −0 src/EdpGithub/Client.php
+0 −0 src/EdpGithub/Collection/Pagination.php
+8 −0 src/EdpGithub/Collection/PaginationInterface.php
+243 −0 src/EdpGithub/Collection/RepositoryCollection.php
+181 −0 src/EdpGithub/Http/Client.php
+8 −0 src/EdpGithub/Http/ClientInterface.php
+46 −0 src/EdpGithub/Listener/Auth/AbstractAuthListener.php
+7 −0 src/EdpGithub/Listener/Auth/Exception/ExceptionInterface.php
+8 −0 src/EdpGithub/Listener/Auth/Exception/InvalidArgumentException.php
+35 −0 src/EdpGithub/Listener/Auth/HttpPassword.php
+35 −0 src/EdpGithub/Listener/Auth/HttpToken.php
+33 −0 src/EdpGithub/Listener/Auth/UrlClientId.php
+32 −0 src/EdpGithub/Listener/Auth/UrlToken.php
+77 −0 src/EdpGithub/Listener/Error.php
+7 −0 src/EdpGithub/Listener/Exception/ExceptionInterface.php
+8 −0 src/EdpGithub/Listener/Exception/InvalidArgumentException.php
+8 −0 src/EdpGithub/Listener/Exception/RuntimeException.php
+108 −0 test/Bootstrap.php
+31 −0 test/EdpGithubTest/Api/CurrentUserTest.php
+23 −0 test/EdpGithubTest/Api/GistTest.php
+23 −0 test/EdpGithubTest/Api/GitDataTest.php
+23 −0 test/EdpGithubTest/Api/IssuesTest.php
+23 −0 test/EdpGithubTest/Api/MarkdownTest.php
+23 −0 test/EdpGithubTest/Api/OrganizationTest.php
+23 −0 test/EdpGithubTest/Api/PullRequestTest.php
+20 −0 test/EdpGithubTest/Api/ReposTest.php
+30 −0 test/EdpGithubTest/Api/TestCase.php
+24 −0 test/EdpGithubTest/Api/UserTest.php
+56 −0 test/EdpGithubTest/ClientTest.php
+221 −0 test/EdpGithubTest/Collection/RepositoryCollectionTest.php
+23 −0 test/EdpGithubTest/Http/ClientTest.php
+73 −0 test/EdpGithubTest/Listener/Auth/HttpPasswordTest.php
+60 −0 test/EdpGithubTest/Listener/Auth/HttpTokenTest.php
+59 −0 test/EdpGithubTest/Listener/Auth/UrlClientIdTest.php
+57 −0 test/EdpGithubTest/Listener/Auth/UrlTokenTest.php
+239 −0 test/EdpGithubTest/Listener/ErrorListenerTest.php
+7 −0 test/TestConfig.php.dist

0 comments on commit 31a067a

Please sign in to comment.