forked from zendframework/modules.zendframework.com
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
209 additions
and
52 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
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
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
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
37 changes: 37 additions & 0 deletions
37
module/Application/test/ApplicationTest/Service/RepositoryTest.php
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,37 @@ | ||
<?php | ||
|
||
namespace ApplicationTest\Service; | ||
|
||
use PHPUnit_Framework_TestCase; | ||
use Application\Service\Repository; | ||
|
||
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'); | ||
|
||
$api->expects($this->once()) | ||
->method('getService') | ||
->with($this->equalTo('Repo')) | ||
->will($this->returnValue('test')); | ||
|
||
$service = new Repository(); | ||
$service->setApi($api); | ||
|
||
$service->getAllRepository('member'); | ||
|
||
|
||
} | ||
} |
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,110 @@ | ||
<?php | ||
namespace ApplicationTest; | ||
|
||
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 | ||
if (is_readable(__DIR__ . '/TestConfig.php')) { | ||
$testConfig = include __DIR__ . '/TestConfig.php'; | ||
} else { | ||
$testConfig = include __DIR__ . '/TestConfig.php.dist'; | ||
} | ||
|
||
$zf2ModulePaths = array(dirname(dirname(__DIR__))); | ||
if (($path = static::findParentPath('vendor'))) { | ||
$zf2ModulePaths[] = $path; | ||
} | ||
if (($path = static::findParentPath('module')) !== $zf2ModulePaths[0]) { | ||
$zf2ModulePaths[] = $path; | ||
} | ||
|
||
if(isset($testConfig['module_listener_options']['module_paths'])) { | ||
$modulePaths = $testConfig['module_listener_options']['module_paths']; | ||
foreach($modulePaths as $modulePath) { | ||
if (($path = static::findParentPath($modulePath)) !== $zf2ModulePaths[0]) { | ||
$zf2ModulePaths[] = $path; | ||
} | ||
} | ||
} | ||
|
||
$zf2ModulePaths = implode(PATH_SEPARATOR, $zf2ModulePaths) . PATH_SEPARATOR; | ||
$zf2ModulePaths .= getenv('ZF2_MODULES_TEST_PATHS') ?: (defined('ZF2_MODULES_TEST_PATHS') ? ZF2_MODULES_TEST_PATHS : ''); | ||
|
||
static::initAutoloader(); | ||
|
||
// use ModuleManager to load this module and it's dependencies | ||
$baseConfig = array( | ||
'module_listener_options' => array( | ||
'module_paths' => explode(PATH_SEPARATOR, $zf2ModulePaths), | ||
), | ||
); | ||
|
||
$config = ArrayUtils::merge($baseConfig, $testConfig); | ||
|
||
$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() | ||
{ | ||
$vendorPath = static::findParentPath('vendor'); | ||
|
||
if (is_readable($vendorPath . '/autoload.php')) { | ||
$loader = include $vendorPath . '/autoload.php'; | ||
} | ||
|
||
$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.'); | ||
} | ||
|
||
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__, | ||
), | ||
), | ||
)); | ||
} | ||
} | ||
|
||
protected static function findParentPath($path) | ||
{ | ||
$dir = __DIR__; | ||
$previousDir = '.'; | ||
while (!is_dir($dir . '/' . $path)) { | ||
$dir = dirname($dir); | ||
if ($previousDir === $dir) return false; | ||
$previousDir = $dir; | ||
} | ||
return $dir . '/' . $path; | ||
} | ||
} | ||
|
||
Bootstrap::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,12 @@ | ||
<?php | ||
return array( | ||
'modules' => array( | ||
'EdpGithub', | ||
'Application', | ||
), | ||
'module_listener_options' => array( | ||
'module_paths' => array( | ||
'moduledev', | ||
), | ||
), | ||
); |
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,7 @@ | ||
<phpunit bootstrap="./Bootstrap.php" colors="true"> | ||
<testsuites> | ||
<testsuite name="Application Module Tests"> | ||
<directory>./ApplicationTest</directory> | ||
</testsuite> | ||
</testsuites> | ||
</phpunit> |
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