예제 #1
0
 /**
  * @param array $files array contains path to migration files
  *
  * @return array
  *
  * @throws \InvalidArgumentException
  */
 private function getMigrationClasses(array $files)
 {
     $versions = array();
     $strtoupper = function ($match) {
         return strtoupper($match[1]);
     };
     foreach ($files as $filePath) {
         if (preg_match('/(([0-9]+)_([a-z0-9_]*)).php$/i', basename($filePath), $match)) {
             $fileName = $match[1];
             $className = 'de\\detert\\sebastian\\slimline\\db\\';
             $className .= ucfirst(preg_replace_callback('/_(.?)/', $strtoupper, strtolower($match[3])));
             $className .= $match[2];
             require_once $filePath;
             if (!class_exists($className)) {
                 throw new \InvalidArgumentException("file '{$filePath}' does not contain class '{$className}'");
             }
             $class = new $className($this->repository->getHandler());
             if (!$class instanceof Migration_Statement) {
                 throw new \InvalidArgumentException("class '{$className}' must extend Migration_Statement");
             }
             $versions[$fileName] = $class;
         }
     }
     ksort($versions);
     return $versions;
 }
예제 #2
0
 /**
  * @covers de\detert\sebastian\slimline\db\Migration_Repository::__construct
  * @covers de\detert\sebastian\slimline\db\Migration_Repository::getHandler
  */
 public function testShouldReturnHandler()
 {
     $repository = new Migration_Repository($this->handler);
     $this->assertSame($this->handler, $repository->getHandler());
 }