Ejemplo n.º 1
0
 protected function _getCache($adapter = 'File')
 {
     @unlink('unit-tests/cache/test-resultset');
     Phalcon\DI::reset();
     $di = new Phalcon\DI();
     $di->set('modelsManager', function () {
         return new Phalcon\Mvc\Model\Manager();
     }, true);
     $di->set('modelsMetadata', function () {
         return new Phalcon\Mvc\Model\Metadata\Memory();
     }, true);
     $di->set('db', function () {
         require 'unit-tests/config.db.php';
         return new Phalcon\Db\Adapter\Pdo\Mysql($configMysql);
     }, true);
     $frontCache = new Phalcon\Cache\Frontend\Data(array('lifetime' => 3600));
     switch ($adapter) {
         case 'File':
             $cache = new Phalcon\Cache\Backend\File($frontCache, array('cacheDir' => 'unit-tests/cache/'));
             break;
         case 'Memcached':
             $cache = new Phalcon\Cache\Backend\Memcache($frontCache, array("host" => "localhost", "port" => "11211"));
             break;
         case 'Libmemcached':
             $cache = new Phalcon\Cache\Backend\Libmemcached($frontCache, array("servers" => array(array("host" => "localhost", "port" => "11211", "weight" => "1"))));
             break;
         default:
             throw new Exception("Unknown cache adapter");
     }
     $di->set('modelsCache', $cache);
     $this->_di = $di;
     return $cache;
 }
Ejemplo n.º 2
0
 public function testBehaviors()
 {
     if (!class_exists('Mongo')) {
         $this->markTestSkipped("Mongo class does not exist, test skipped");
         return;
     }
     Phalcon\DI::reset();
     $di = new Phalcon\DI();
     $di->set('mongo', function () {
         $mongo = new MongoClient();
         return $mongo->phalcon_test;
     });
     $di->set('collectionManager', function () {
         return new Phalcon\Mvc\Collection\Manager();
     });
     //Timestampable
     $subscriber = new Subs();
     $subscriber->email = '*****@*****.**';
     $subscriber->status = 'I';
     $this->assertTrue($subscriber->save());
     $this->assertEquals(preg_match('/[0-9]{4}-[0-9]{2}-[0-9]{2}/', $subscriber->created_at), 1);
     //Softdelete
     $subscriber = Subs::findFirst();
     $this->assertTrue($subscriber->delete());
     $this->assertEquals($subscriber->status, 'D');
     $this->assertEquals(Subs::count(), 1);
 }
Ejemplo n.º 3
0
 public function testApplicationModulesDefinitionClosure()
 {
     // Creates the autoloader
     $loader = new \Phalcon\Loader();
     $loader->registerNamespaces(array('Frontend\\Controllers' => __DIR__ . '/modules/frontend/controllers/', 'Backend\\Controllers' => __DIR__ . '/modules/backend/controllers/'));
     $loader->register();
     $_GET['_url'] = '/login';
     Phalcon\DI::reset();
     $di = new Phalcon\DI\FactoryDefault();
     $di->set('router', function () {
         $router = new Phalcon\Mvc\Router(false);
         $router->add('/index', array('controller' => 'index', 'module' => 'frontend', 'namespace' => 'Frontend\\Controllers\\'));
         $router->add('/login', array('controller' => 'login', 'module' => 'backend', 'namespace' => 'Backend\\Controllers\\'));
         return $router;
     });
     $application = new Phalcon\Mvc\Application();
     $view = new \Phalcon\Mvc\View();
     $application->registerModules(array('frontend' => function ($di) use($view) {
         $di->set('view', function () use($view) {
             $view = new \Phalcon\Mvc\View();
             $view->setViewsDir(__DIR__ . '/modules/frontend/views/');
             return $view;
         });
     }, 'backend' => function ($di) use($view) {
         $di->set('view', function () use($view) {
             $view->setViewsDir(__DIR__ . '/modules/backend/views/');
             return $view;
         });
     }));
     $application->setDi($di);
     $this->assertEquals($application->handle()->getContent(), '<html>here</html>' . PHP_EOL);
     $loader->unregister();
 }
Ejemplo n.º 4
0
 protected function _prepareDI(&$trace)
 {
     Phalcon\DI::reset();
     $eventsManager = new Phalcon\Events\Manager();
     $eventsManager->attach('model', function ($event, $model) use(&$trace) {
         if (!isset($trace[$event->getType()][get_class($model)])) {
             $trace[$event->getType()][get_class($model)] = 1;
         } else {
             $trace[$event->getType()][get_class($model)]++;
         }
     });
     $di = new Phalcon\DI();
     $di->set('modelsManager', function () use($eventsManager) {
         $modelsManager = new Phalcon\Mvc\Model\Manager();
         $modelsManager->setEventsManager($eventsManager);
         return $modelsManager;
     }, true);
     $di->set('modelsMetadata', function () {
         return new Phalcon\Mvc\Model\Metadata\Memory();
     }, true);
     $di->set('db', function () {
         require 'unit-tests/config.db.php';
         //return new Phalcon\Db\Adapter\Pdo\Mysql($configMysql);
         return new Twm\Db\Adapter\Pdo\Mssql($configMssql);
     }, true);
 }
Ejemplo n.º 5
0
 protected function _getDI($dbService)
 {
     Phalcon\DI::reset();
     $di = new Phalcon\DI\FactoryDefault();
     $di->set('db', $dbService, true);
     return $di;
 }
Ejemplo n.º 6
0
 public function testCollectionsEvents()
 {
     if (!class_exists('Mongo')) {
         $this->markTestSkipped("Mongo class does not exist, test skipped");
         return;
     }
     Phalcon\DI::reset();
     $di = new Phalcon\DI();
     $di->set('mongo', function () {
         $mongo = new Mongo();
         return $mongo->phalcon_test;
     });
     $di->set('collectionManager', function () {
         return new Phalcon\Mvc\Collection\Manager();
     });
     $songs = Store\Songs::find();
     $this->assertTrue(is_array($songs));
     foreach ($songs as $song) {
         $this->assertTrue($song->delete());
     }
     $trace = array();
     $song = new Store\Songs();
     $song->trace =& $trace;
     $song->artist = 'Radiohead';
     $song->name = 'Lotus Flower';
     $this->assertTrue($song->save());
     $this->assertEquals($trace, array('Store\\Songs::beforeValidation' => 1, 'Store\\Songs::beforeValidationOnCreate' => 1, 'Store\\Songs::afterValidationOnCreate' => 1, 'Store\\Songs::afterValidation' => 1, 'Store\\Songs::beforeSave' => 1, 'Store\\Songs::beforeCreate' => 1, 'Store\\Songs::afterCreate' => 1, 'Store\\Songs::afterSave' => 1));
     $this->assertTrue($song->save());
     $this->assertEquals($trace, array('Store\\Songs::beforeValidation' => 2, 'Store\\Songs::beforeValidationOnCreate' => 1, 'Store\\Songs::afterValidationOnCreate' => 1, 'Store\\Songs::afterValidation' => 2, 'Store\\Songs::beforeSave' => 2, 'Store\\Songs::beforeCreate' => 1, 'Store\\Songs::afterCreate' => 1, 'Store\\Songs::afterSave' => 2, 'Store\\Songs::afterValidationOnUpdate' => 1, 'Store\\Songs::beforeUpdate' => 1, 'Store\\Songs::afterUpdate' => 1));
 }
 protected function _prepareDI()
 {
     Phalcon\DI::reset();
     $di = new Phalcon\DI();
     $di->set('modelsManager', function () {
         return new Phalcon\Mvc\Model\Manager();
     }, true);
     $di->set('modelsMetadata', function () {
         return new Phalcon\Mvc\Model\Metadata\Memory();
     }, true);
     $di->set('modelsQuery', 'Phalcon\\Mvc\\Model\\Query');
     $di->set('modelsQueryBuilder', 'Phalcon\\Mvc\\Model\\Query\\Builder');
     $di->set('modelsCriteria', 'Phalcon\\Mvc\\Model\\Criteria');
     $di->set('db', function () {
         throw new Exception('Using default database source');
     }, true);
     $di->set('dbOne', function () {
         require 'unit-tests/config.db.php';
         return new Phalcon\Db\Adapter\Pdo\Mysql($configMysql);
     }, true);
     $di->set('dbTwo', function () {
         require 'unit-tests/config.db.php';
         return new Phalcon\Db\Adapter\Pdo\Mysql($configMysql);
     }, true);
 }
Ejemplo n.º 8
0
 protected function _prepareDI()
 {
     Phalcon\DI::reset();
     $di = new Phalcon\DI();
     $di->set('modelsManager', function () {
         return new Phalcon\Mvc\Model\Manager();
     }, true);
     $di->set('db', function () {
         require 'unit-tests/config.db.php';
         return new Phalcon\Db\Adapter\Pdo\Mysql($configMysql);
     }, true);
 }
Ejemplo n.º 9
0
 protected function _getDI()
 {
     Phalcon\DI::reset();
     $di = new Phalcon\DI();
     $di->set('modelsManager', function () {
         return new Phalcon\Mvc\Model\Manager();
     });
     $di->set('modelsMetadata', function () {
         return new Phalcon\Mvc\Model\Metadata\Memory();
     });
     return $di;
 }
Ejemplo n.º 10
0
 public static function setUpBeforeClass()
 {
     Phalcon\DI::reset();
     $di = new Phalcon\DI();
     $di->set('mongo', function () {
         $mongo = new MongoClient();
         return $mongo->phalcon_test;
     });
     $di->set('collectionManager', function () {
         return new Phalcon\Mvc\Collection\Manager();
     });
 }
 public function testOverrideStaticCache()
 {
     require 'unit-tests/config.db.php';
     if (empty($configMysql)) {
         $this->markTestSkipped('Test skipped');
         return;
     }
     Phalcon\DI::reset();
     $di = new Phalcon\DI();
     $di['db'] = function () {
         require 'unit-tests/config.db.php';
         return new Phalcon\Db\Adapter\Pdo\Mysql($configMysql);
     };
     $di['modelsManager'] = function () {
         return new Phalcon\Mvc\Model\Manager();
     };
     $di['modelsMetadata'] = function () {
         return new Phalcon\Mvc\Model\Metadata\Memory();
     };
     $di->set('modelsQuery', 'Phalcon\\Mvc\\Model\\Query');
     $di->set('modelsQueryBuilder', 'Phalcon\\Mvc\\Model\\Query\\Builder');
     $di->set('modelsCriteria', 'Phalcon\\Mvc\\Model\\Criteria');
     $di['modelsCache'] = function () {
         $frontCache = new Phalcon\Cache\Frontend\Data();
         return new Phalcon\Cache\Backend\File($frontCache, array('cacheDir' => 'unit-tests/cache/'));
     };
     $robot = Cacheable\Robots::findFirst(2);
     $this->assertEquals(get_class($robot), 'Cacheable\\Robots');
     $robot = Cacheable\Robots::findFirst(2);
     $this->assertEquals(get_class($robot), 'Cacheable\\Robots');
     $robot = Cacheable\Robots::findFirst(array('id = 2'));
     $this->assertEquals(get_class($robot), 'Cacheable\\Robots');
     $robot = Cacheable\Robots::findFirst(array('id = 2'));
     $this->assertEquals(get_class($robot), 'Cacheable\\Robots');
     $robot = Cacheable\Robots::findFirst(array('order' => 'id DESC'));
     $this->assertEquals(get_class($robot), 'Cacheable\\Robots');
     $robot = Cacheable\Robots::findFirst(array('order' => 'id DESC'));
     $this->assertEquals(get_class($robot), 'Cacheable\\Robots');
     $robot = Cacheable\Robots::findFirst(1);
     $this->assertEquals(get_class($robot), 'Cacheable\\Robots');
     $robotParts = $robot->getRobotsParts();
     $this->assertEquals(get_class($robotParts), 'Phalcon\\Mvc\\Model\\Resultset\\Simple');
     $robotParts = $robot->getRobotsParts();
     $this->assertEquals(get_class($robotParts), 'Phalcon\\Mvc\\Model\\Resultset\\Simple');
     $part = $robotParts[0]->getParts();
     $this->assertEquals(get_class($part), 'Cacheable\\Parts');
     $part = $robotParts[0]->getParts();
     $this->assertEquals(get_class($part), 'Cacheable\\Parts');
     $robot = $robotParts[0]->getRobots();
     $this->assertEquals(get_class($robot), 'Cacheable\\Robots');
     $robot = $robotParts[0]->getRobots();
     $this->assertEquals(get_class($robot), 'Cacheable\\Robots');
 }
 protected function _getDI()
 {
     Phalcon\DI::reset();
     $di = new Phalcon\DI();
     $di->set('modelsManager', function () {
         return new Phalcon\Mvc\Model\Manager();
     });
     $di->set('db', function () {
         require __DIR__ . '/config.db.php';
         return new Phalcon\Db\Adapter\Pdo\Mysql($configMysql);
     });
     return $di;
 }
Ejemplo n.º 13
0
 public function testMicroEvents()
 {
     Phalcon\DI::reset();
     $trace = array();
     $eventsManager = new Phalcon\Events\Manager();
     $eventsManager->attach('micro', function ($event) use(&$trace) {
         $trace[$event->getType()] = true;
     });
     $app = new Phalcon\Mvc\Micro();
     $app->setEventsManager($eventsManager);
     $app->map('/blog', function () {
     });
     $app->handle('/blog');
     $this->assertEquals($trace, array('beforeHandleRoute' => true, 'beforeExecuteRoute' => true, 'afterExecuteRoute' => true, 'afterHandleRoute' => true));
 }
Ejemplo n.º 14
0
 protected function _getDI()
 {
     Phalcon\DI::reset();
     $di = new Phalcon\DI();
     $di->set('modelsManager', function () {
         return new Phalcon\Mvc\Model\Manager();
     }, true);
     $di->set('modelsMetadata', function () {
         return new Phalcon\Mvc\Model\Metadata\Memory();
     }, true);
     $di->set('modelsQuery', 'Phalcon\\Mvc\\Model\\Query');
     $di->set('modelsQueryBuilder', 'Phalcon\\Mvc\\Model\\Query\\Builder');
     $di->set('modelsCriteria', 'Phalcon\\Mvc\\Model\\Criteria');
     return $di;
 }
Ejemplo n.º 15
0
 protected function _prepareDI()
 {
     Phalcon\DI::reset();
     $di = new Phalcon\DI();
     $di->set('modelsManager', function () {
         return new Phalcon\Mvc\Model\Manager();
     }, true);
     $di->set('modelsMetadata', function () {
         return new Phalcon\Mvc\Model\Metadata\Memory();
     }, true);
     $di->set('db', function () {
         require __DIR__ . '/config.db.php';
         return new Phalcon\Db\Adapter\Pdo\Mysql($configMysql);
     }, true);
 }
Ejemplo n.º 16
0
 /**
  * Tests the notFound
  *
  * @issue T169
  * @author Nikos Dimopoulos <*****@*****.**>
  * @since 2012-11-06
  */
 public function testMicroNotFound_T169()
 {
     Phalcon\DI::reset();
     $handler = new RestHandler($this);
     $app = new \Phalcon\Mvc\Micro();
     $app->get('/api/site', array($handler, 'find'));
     $app->post('/api/site/save', array($handler, 'save'));
     $flag = false;
     $app->notFound(function () use(&$flag) {
         $flag = true;
     });
     $_SERVER['REQUEST_METHOD'] = 'GET';
     $_GET['_url'] = '/fourohfour';
     $app->handle();
     $this->assertTrue($flag);
 }
 protected function _getDI()
 {
     Phalcon\DI::reset();
     $di = new Phalcon\DI();
     $di['modelsManager'] = function () {
         return new Phalcon\Mvc\Model\Manager();
     };
     $di['db'] = function () {
         require __DIR__ . '/config.db.php';
         return new Phalcon\Db\Adapter\Pdo\Mysql($configMysql);
     };
     $di['annotations'] = function () {
         return new Phalcon\Annotations\Adapter\Memory();
     };
     return $di;
 }
Ejemplo n.º 18
0
 protected function _getDI()
 {
     Phalcon\DI::reset();
     $di = new Phalcon\DI();
     $di->set('modelsManager', function () {
         return new Phalcon\Mvc\Model\Manager();
     });
     $di->set('modelsMetadata', function () {
         return new Phalcon\Mvc\Model\Metadata\Memory();
     });
     $di->set('db', function () {
         require 'unit-tests/config.db.php';
         return new Phalcon\Db\Adapter\Pdo\Mysql($configMysql);
     });
     return $di;
 }
 protected function _getDI()
 {
     Phalcon\DI::reset();
     $di = new Phalcon\DI();
     $di->set('modelsManager', function () {
         return new Phalcon\Mvc\Model\Manager();
     });
     $di->set('modelsQuery', 'Phalcon\\Mvc\\Model\\Query');
     $di->set('modelsQueryBuilder', 'Phalcon\\Mvc\\Model\\Query\\Builder');
     $di->set('modelsCriteria', 'Phalcon\\Mvc\\Model\\Criteria');
     $di->set('db', function () {
         require 'unit-tests/config.db.php';
         return new Phalcon\Db\Adapter\Pdo\Mysql($configMysql);
     }, true);
     return $di;
 }
Ejemplo n.º 20
0
 public function testCollectionsEvents()
 {
     if (!class_exists('Mongo')) {
         $this->markTestSkipped("Mongo class does not exist, test skipped");
         return;
     }
     Phalcon\DI::reset();
     $di = new Phalcon\DI();
     $di->set('mongo', function () {
         $mongo = new MongoClient();
         return $mongo->phalcon_test;
     });
     $di->set('collectionManager', function () {
         return new Phalcon\Mvc\Collection\Manager();
     });
     $songs = Store\Songs::find();
     $this->assertTrue(is_array($songs));
     foreach ($songs as $song) {
         $this->assertTrue($song->delete());
     }
     $trace = array();
     $song = new Songs();
     $song->artist = 'Radiohead';
     $song->name = 'Lotus Flower';
     $this->assertTrue($song->save());
     $serialized = serialize($song);
     $song = unserialize($serialized);
     $this->assertEquals($song->artist, 'Radiohead');
     $this->assertEquals($song->name, 'Lotus Flower');
     $this->assertTrue($song->save());
     $song = Songs::findFirst();
     $serialized = serialize($song);
     $song = unserialize($serialized);
     $this->assertEquals($song->artist, 'Radiohead');
     $this->assertEquals($song->name, 'Lotus Flower');
     $this->assertTrue($song->save());
     $song = new Songs();
     $song->artist = 'Massive Attack';
     $song->name = 'Paradise Circus';
     $this->assertTrue($song->save());
     $songs = Songs::find();
     $this->assertEquals(count($songs), 2);
     $serialized = serialize($songs);
     $songs = unserialize($serialized);
     $this->assertEquals(count($songs), 2);
 }
 public function testOverrideStaticCache()
 {
     Phalcon\DI::reset();
     $di = new Phalcon\DI();
     $di['db'] = function () {
         require __DIR__ . '/config.db.php';
         return new Phalcon\Db\Adapter\Pdo\Mysql($configMysql);
     };
     $di['modelsManager'] = function () {
         return new Phalcon\Mvc\Model\Manager();
     };
     $di['modelsMetadata'] = function () {
         return new Phalcon\Mvc\Model\Metadata\Memory();
     };
     $di['modelsCache'] = function () {
         $frontCache = new Phalcon\Cache\Frontend\Data();
         return new Phalcon\Cache\Backend\File($frontCache, array('cacheDir' => __DIR__ . '/cache/'));
     };
     $robot = Cacheable\Robots::findFirst(2);
     $this->assertEquals(get_class($robot), 'Cacheable\\Robots');
     $robot = Cacheable\Robots::findFirst(2);
     $this->assertEquals(get_class($robot), 'Cacheable\\Robots');
     $robot = Cacheable\Robots::findFirst(array('id = 2'));
     $this->assertEquals(get_class($robot), 'Cacheable\\Robots');
     $robot = Cacheable\Robots::findFirst(array('id = 2'));
     $this->assertEquals(get_class($robot), 'Cacheable\\Robots');
     $robot = Cacheable\Robots::findFirst(array('order' => 'id DESC'));
     $this->assertEquals(get_class($robot), 'Cacheable\\Robots');
     $robot = Cacheable\Robots::findFirst(array('order' => 'id DESC'));
     $this->assertEquals(get_class($robot), 'Cacheable\\Robots');
     $robot = Cacheable\Robots::findFirst(1);
     $this->assertEquals(get_class($robot), 'Cacheable\\Robots');
     $robotParts = $robot->getRobotsParts();
     $this->assertEquals(get_class($robotParts), 'Phalcon\\Mvc\\Model\\Resultset\\Simple');
     $robotParts = $robot->getRobotsParts();
     $this->assertEquals(get_class($robotParts), 'Phalcon\\Mvc\\Model\\Resultset\\Simple');
     $part = $robotParts[0]->getParts();
     $this->assertEquals(get_class($part), 'Cacheable\\Parts');
     $part = $robotParts[0]->getParts();
     $this->assertEquals(get_class($part), 'Cacheable\\Parts');
     $robot = $robotParts[0]->getRobots();
     $this->assertEquals(get_class($robot), 'Cacheable\\Robots');
     $robot = $robotParts[0]->getRobots();
     $this->assertEquals(get_class($robot), 'Cacheable\\Robots');
 }
Ejemplo n.º 22
0
 public function testUrl()
 {
     Phalcon\DI::reset();
     //Create a default DI
     $di = new Phalcon\DI();
     $di['router'] = function () {
         $router = new \Phalcon\Mvc\Router(FALSE);
         $router->add('/:controller/:action', array('controller' => 1, 'action' => 2))->setHostName('phalconphp.com')->setName('test');
         return $router;
     };
     $di->set('url', function () {
         $url = new Phalcon\Mvc\Url();
         $url->setBaseUri('/');
         return $url;
     });
     $url = $di->url->get(array('for' => 'test', 'hostname' => true, 'controller' => 'index', 'action' => 'test'));
     $this->assertEquals($url, 'phalconphp.com/index/test');
 }
Ejemplo n.º 23
0
 protected function _loadDI()
 {
     Phalcon\DI::reset();
     $di = new Phalcon\DI();
     $di->set('modelsManager', function () {
         return new Phalcon\Mvc\Model\Manager();
     });
     $di->set('modelsMetadata', function () {
         return new Phalcon\Mvc\Model\Metadata\Memory();
     });
     $di->set('modelsQuery', 'Phalcon\\Mvc\\Model\\Query');
     $di->set('modelsQueryBuilder', 'Phalcon\\Mvc\\Model\\Query\\Builder');
     $di->set('modelsCriteria', 'Phalcon\\Mvc\\Model\\Criteria');
     $di->set('db', function () {
         require 'unit-tests/config.db.php';
         return new Phalcon\Db\Adapter\Pdo\Mysql($configMysql);
     }, true);
     /*$di->set('db', function() {
     
     		    $eventsManager = new EventsManager();
     
     		    $logger = new FileLogger("debug.log");
     
     		    //Listen all the database events
     		    $eventsManager->attach('db', function($event, $connection) use ($logger) {
     		        if ($event->getType() == 'beforeQuery') {
     		            $logger->log($connection->getSQLStatement(), \Phalcon\Logger::INFO);
     		        }
     		    });
     
     		    $connection = new DbAdapter(array(
     		        "host" => "localhost",
     		        "username" => "root",
     		        "password" => "",
     		        "dbname" => "phalcon_test"
     		    ));
     
     		    //Assign the eventsManager to the db adapter instance
     		    $connection->setEventsManager($eventsManager);
     
     		    return $connection;
     		}, true);*/
     return $di;
 }
 protected function _prepareDI()
 {
     Phalcon\DI::reset();
     $di = new Phalcon\DI();
     $di->set('modelsManager', function () {
         return new Phalcon\Mvc\Model\Manager();
     }, true);
     $di->set('modelsMetadata', function () {
         return new Phalcon\Mvc\Model\Metadata\Memory();
     }, true);
     $di->set('db', function () {
         throw new Exception('Using default database source');
     });
     $di->set('dbOne', function () {
         require __DIR__ . '/config.db.php';
         return new Phalcon\Db\Adapter\Pdo\Mysql($configMysql);
     });
     $di->set('dbTwo', function () {
         require __DIR__ . '/config.db.php';
         return new Phalcon\Db\Adapter\Pdo\Mysql($configMysql);
     });
 }
Ejemplo n.º 25
0
 public function testCollections()
 {
     if (!class_exists('Mongo')) {
         $this->markTestSkipped("Mongo class does not exist, test skipped");
         return;
     }
     Phalcon\DI::reset();
     $di = new Phalcon\DI();
     $di->set('mongo', function () {
         $mongo = new MongoClient();
         return $mongo->phalcon_test;
     });
     $di->set('collectionManager', function () {
         return new Phalcon\Mvc\Collection\Manager();
     });
     $songs = Songs::find();
     $this->assertTrue(is_array($songs));
     foreach ($songs as $song) {
         $this->assertTrue($song->delete());
     }
     $song = new Songs();
     $song->artist = 'Radiohead';
     $song->name = 'Lotus Flower';
     $success = $song->save();
     $this->assertTrue($success);
     $this->assertInstanceOf('MongoId', $song->_id);
     $firstSongId = $song->_id;
     $songs = Songs::find();
     $this->assertTrue(is_array($songs));
     $this->assertEquals(count($songs), 1);
     $this->assertEquals($songs[0]->name, 'Lotus Flower');
     $this->assertEquals($songs[0]->artist, 'Radiohead');
     $song = new Songs();
     $song->artist = 'Massive Attack';
     $song->name = 'Teardrop';
     $success = $song->save();
     $this->assertTrue($success);
     $this->assertInstanceOf('MongoId', $song->_id);
     $this->assertNotEquals((string) $firstSongId->{'$id'}, (string) $song->_id->{'$id'});
     $secondSongId = $song->_id;
     $songs = Songs::find();
     $this->assertTrue(is_array($songs));
     $this->assertEquals(count($songs), 2);
     $this->assertEquals($songs[0]->name, 'Lotus Flower');
     $this->assertEquals($songs[0]->artist, 'Radiohead');
     $this->assertEquals($songs[1]->name, 'Teardrop');
     $this->assertEquals($songs[1]->artist, 'Massive Attack');
     $song = new Songs();
     $song->artist = 'Massive Attack';
     $song->name = 'Paradise Circus';
     $success = $song->save();
     $this->assertTrue($success);
     $this->assertInstanceOf('MongoId', $song->_id);
     $this->assertNotEquals((string) $firstSongId->{'$id'}, (string) $song->_id->{'$id'});
     $this->assertNotEquals((string) $secondSongId->{'$id'}, (string) $song->_id->{'$id'});
     $songs = Songs::find();
     $this->assertTrue(is_array($songs));
     $this->assertEquals(count($songs), 3);
     $song = Songs::findFirst();
     $this->assertInstanceOf('Songs', $song);
     $this->assertEquals($song->name, 'Lotus Flower');
     $this->assertEquals($song->artist, 'Radiohead');
     $song = Songs::findFirst(array(array('artist' => 'Massive Attack')));
     $this->assertInstanceOf('Songs', $song);
     $this->assertEquals($song->artist, 'Massive Attack');
     $song = Songs::findFirst(array('conditions' => array('artist' => 'Massive Attack')));
     $this->assertInstanceOf('Songs', $song);
     $this->assertEquals($song->artist, 'Massive Attack');
     $song = Songs::findFirst(array('conditions' => array('name' => 'Paradise Circus')));
     $this->assertInstanceOf('Songs', $song);
     $this->assertEquals($song->name, 'Paradise Circus');
     //No results
     $song = Songs::findFirst(array(array('artist' => 'Lana')));
     $this->assertFalse($song);
     $song = Songs::findFirst(array('conditions' => array('artist' => 'Lana')));
     $this->assertFalse($song);
     $song = Songs::findFirst(array(array('artist' => 'Lana')));
     $this->assertFalse($song);
     //Passing parameters to find
     $songs = Songs::find(array(array('artist' => 'Massive Attack')));
     $this->assertTrue(is_array($songs));
     $this->assertEquals(count($songs), 2);
     $this->assertEquals($songs[0]->name, 'Teardrop');
     $this->assertEquals($songs[1]->name, 'Paradise Circus');
     $songs = Songs::find(array('conditions' => array('artist' => 'Massive Attack')));
     $this->assertTrue(is_array($songs));
     $this->assertEquals(count($songs), 2);
     $this->assertEquals($songs[0]->name, 'Teardrop');
     $this->assertEquals($songs[1]->name, 'Paradise Circus');
     $songs = Songs::find(array('conditions' => array('artist' => 'Massive Attack'), 'sort' => array('name' => 1)));
     $this->assertTrue(is_array($songs));
     $this->assertEquals(count($songs), 2);
     $this->assertEquals($songs[0]->name, 'Paradise Circus');
     $this->assertEquals($songs[1]->name, 'Teardrop');
     $songs = Songs::find(array('conditions' => array('artist' => 'Massive Attack'), 'sort' => array('name' => 1), 'limit' => 1));
     $this->assertTrue(is_array($songs));
     $this->assertEquals(count($songs), 1);
     $this->assertEquals($songs[0]->name, 'Paradise Circus');
     $songs = Songs::find(array('conditions' => array('artist' => 'Massive Attack'), 'limit' => 1));
     $this->assertTrue(is_array($songs));
     $this->assertEquals(count($songs), 1);
     $this->assertEquals($songs[0]->name, 'Teardrop');
     //Find first
     $song = Songs::findFirst(array(array('artist' => 'Massive Attack')));
     $this->assertInstanceOf('Songs', $song);
     $this->assertEquals($song->name, 'Teardrop');
     $song = Songs::findFirst(array('conditions' => array('artist' => 'Massive Attack')));
     $this->assertInstanceOf('Songs', $song);
     $this->assertEquals($song->name, 'Teardrop');
     //Count
     $this->assertEquals(Songs::count(), 3);
     $this->assertEquals(Songs::count(array(array('artist' => 'Massive Attack'))), 2);
 }
Ejemplo n.º 26
0
 public function testIssues2270()
 {
     Phalcon\DI::reset();
     $di = new \Phalcon\DI();
     $dispatcher = new \Phalcon\Mvc\Dispatcher();
     $dispatcher->setDI($di);
     $dispatcher->setDefaultNamespace('A\\B\\C');
     $dispatcher->setControllerName('Test');
     $dispatcher->setActionName('index');
     $this->assertEquals('A\\B\\C\\TestController', $dispatcher->getHandlerClass());
 }
Ejemplo n.º 27
0
 public function setUp()
 {
     Phalcon\DI::reset();
     $this->_di = new \Phalcon\DI();
 }
Ejemplo n.º 28
0
 public function testFilterMultiplesSourcesFilterJoin()
 {
     @unlink(__DIR__ . '/assets/production/combined-3.js');
     Phalcon\DI::reset();
     $di = new Phalcon\DI();
     $di['url'] = function () {
         $url = new Phalcon\Mvc\Url();
         $url->setStaticBaseUri('/');
         return $url;
     };
     $assets = new Phalcon\Assets\Manager();
     $assets->useImplicitOutput(false);
     $js = $assets->collection('js');
     $js->setTargetUri('production/combined-3.js');
     $js->setTargetPath(__DIR__ . '/assets/production/combined-3.js');
     $jquery = new Phalcon\Assets\Resource\Js(__DIR__ . '/assets/jquery.js', false, false);
     $jquery->setTargetUri('jquery.js');
     $js->add($jquery);
     $gs = new Phalcon\Assets\Resource\Js(__DIR__ . '/assets/gs.js');
     $gs->setTargetUri('gs.js');
     $gs->setTargetPath('gs.js');
     $js->add($gs);
     $js->join(true);
     //Use two filters
     $js->addFilter(new Phalcon\Assets\Filters\None());
     $js->addFilter(new Phalcon\Assets\Filters\None());
     $this->assertEquals($assets->outputJs('js'), '<script src="/production/combined-3.js" type="text/javascript"></script>' . PHP_EOL);
 }
Ejemplo n.º 29
0
 public function testMicroCollectionsLazy()
 {
     Phalcon\DI::reset();
     $app = new Phalcon\Mvc\Micro();
     $collection = new Phalcon\Mvc\Micro\Collection();
     $collection->setHandler('PersonasLazyController', true);
     $collection->map('/', 'index');
     $collection->map('/edit/{number}', 'edit');
     $app->mount($collection);
     $app->handle('/');
     $this->assertEquals(PersonasLazyController::getEntered(), 1);
     $app->handle('/edit/100');
     $this->assertEquals(PersonasLazyController::getEntered(), 101);
 }
Ejemplo n.º 30
-1
 protected function _getDI()
 {
     Phalcon\DI::reset();
     $di = new Phalcon\DI();
     $di->set('modelsManager', function () {
         return new Phalcon\Mvc\Model\Manager();
     });
     $di->set('modelsMetadata', function () {
         return new Phalcon\Mvc\Model\Metadata\Memory();
     });
     $di->set('db', function () {
         require 'unit-tests/config.db.php';
         //return new Twm\Db\Adapter\Pdo\Mssql($configMssql);
         $connection = new Phalcon\Db\Adapter\Pdo\Mysql($configMysql);
         $eventsManager = new Phalcon\Events\Manager();
         //Listen all the database events
         $eventsManager->attach('db', function ($event, $connection) {
             if ($event->getType() == 'beforeQuery') {
                 echo $connection->getSQLStatement();
             }
         });
         //Assign the eventsManager to the db adapter instance
         $connection->setEventsManager($eventsManager);
         return $connection;
     });
     return $di;
 }