-
Notifications
You must be signed in to change notification settings - Fork 3
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
18 changed files
with
1,125 additions
and
39 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 |
---|---|---|
|
@@ -159,4 +159,5 @@ | |
), | ||
), | ||
), | ||
'autorize_user' => true, | ||
); |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
<?php | ||
namespace PlaygroundGalleryTest; | ||
|
||
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; | ||
protected static $config; | ||
protected static $bootstrap; | ||
|
||
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(); | ||
|
||
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[] = $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; | ||
|
||
static::$config = $config; | ||
|
||
// disable FirePHP for Unit testing | ||
//$firephp = \FirePHP::getInstance(true); | ||
//$firephp->setEnabled(false); | ||
} | ||
|
||
public static function getServiceManager() | ||
{ | ||
return static::$serviceManager; | ||
} | ||
|
||
public static function getConfig() | ||
{ | ||
return static::$config; | ||
} | ||
|
||
|
||
|
||
protected static function initAutoloader() | ||
{ | ||
$vendorPath = static::findParentPath('vendor'); | ||
|
||
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)); | ||
|
||
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'; | ||
|
||
} | ||
|
||
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(); | ||
|
||
// let's avoid session_start(): Cannot send session cookie - headers already sent by | ||
ob_start(); |
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,98 @@ | ||
<?php | ||
namespace PlaygroundGalleryTest\Mapper; | ||
|
||
use PlaygroundGalleryTest\Bootstrap; | ||
use \PlaygroundGallery\Entity\Category as CategoryEntity; | ||
|
||
class CategoryTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* Service Manager | ||
* @var Zend\ServiceManager\ServiceManager | ||
*/ | ||
protected $sm; | ||
|
||
/** | ||
* Doctrine Entity Manager | ||
* @var Doctrine\ORM\EntityManager | ||
*/ | ||
protected $em; | ||
|
||
/** | ||
* Category sample | ||
* @var Array | ||
*/ | ||
protected $categoryData; | ||
|
||
public function setUp() | ||
{ | ||
$this->sm = Bootstrap::getServiceManager(); | ||
$this->em = $this->sm->get('doctrine.entitymanager.orm_default'); | ||
$tool = new \Doctrine\ORM\Tools\SchemaTool($this->em); | ||
$classes = $this->em->getMetadataFactory()->getAllMetadata(); | ||
$tool->dropSchema($classes); | ||
$tool->createSchema($classes); | ||
|
||
$this->categoryData = array( | ||
'name' => 'CeciEstUnTitre', | ||
); | ||
|
||
parent::setUp(); | ||
} | ||
|
||
public function testCanInsertNewRecord() | ||
{ | ||
$category = new CategoryEntity(); | ||
$category->populate($this->categoryData); | ||
|
||
// save data | ||
$this->em->persist($category); | ||
$this->em->flush(); | ||
|
||
$this->assertEquals($this->categoryData['name'], $category->getName()); | ||
|
||
return $category->getId(); | ||
} | ||
|
||
/** | ||
* @depends testCanInsertNewRecord | ||
*/ | ||
public function testCanUpdateInsertedRecord($id) | ||
{ | ||
$data = array( | ||
'id' => $id | ||
); | ||
$category = $this->em->getRepository('PlaygroundGallery\Entity\Category')->find($id); | ||
$this->assertInstanceOf('PlaygroundGallery\Entity\Category', $category); | ||
$this->assertEquals($this->categoryData['name'], $category->getName()); | ||
|
||
$category->populate($data); | ||
$this->em->flush(); | ||
|
||
$this->assertEquals($this->categoryData['name'], $category->getName()); | ||
} | ||
|
||
/** | ||
* @depends testCanInsertNewRecord | ||
*/ | ||
public function testCanRemoveInsertedRecord($id) | ||
{ | ||
$category = $this->em->getRepository('PlaygroundGallery\Entity\Category')->find($id); | ||
$this->assertInstanceOf('PlaygroundGallery\Entity\Category', $category); | ||
|
||
$this->em->remove($category); | ||
$this->em->flush(); | ||
|
||
$category = $this->em->getRepository('PlaygroundGallery\Entity\Category')->find($id); | ||
$this->assertEquals(false, $category); | ||
} | ||
|
||
public function tearDown() | ||
{ | ||
$dbh = $this->em->getConnection(); | ||
|
||
unset($this->sm); | ||
unset($this->em); | ||
parent::tearDown(); | ||
} | ||
} |
Oops, something went wrong.