/** * @internal */ public function __construct() { // call PHPMailer constructor with throw exceptions param parent::__construct(true); $app = TipyApp::getInstance(); $path = $app->config->get('mail_sendmail_path'); ini_set('sendmail_path', $path); $this->isSendmail(); }
public static function run() { CLI_MODE && die("TipyApp cannot be run in CLI mode\n"); ob_start(); $app = TipyApp::getInstance(); $app->run(); ob_end_flush(); }
public function tearDown() { $app = TipyApp::getInstance(); $app->db->query('TRUNCATE TABLE records'); }
/** * Instantiate controller with application context */ public function __construct() { $app = TipyApp::getInstance(); $this->config = $app->config; $this->request = $app->request; $this->in = $app->in; $this->out = $app->out; $this->env = $app->env; $this->cookie = $app->cookie; $this->view = $app->view; $this->db = $app->db; $this->session = $app->session; $this->flash = new TipyFlash($this->session); }
/** * Rollback transaction * @throws TipyDaoException if there is no transaction in progress * @return mysqli_result */ private static function rollbackTransaction($kind = 'soft') { $app = TipyApp::getInstance(); if (self::$openTransactionsCount == 0) { throw new TipyDaoException('No transaction in progress'); } elseif ($kind == 'hard') { // rollback parent transaction with all nested savepoints $app->logger->debug('ROLLBACK'); $result = $app->db->query('ROLLBACK'); if ($result) { self::$openTransactionsCount = 0; } } elseif (self::$openTransactionsCount == 1) { $app->logger->debug('ROLLBACK'); $result = $app->db->query('ROLLBACK'); if ($result) { self::$openTransactionsCount = 0; } } elseif (self::$openTransactionsCount > 1) { $app->logger->debug('ROLLBACK TO SAVEPOINT ' . self::currentSavepointName()); $result = $app->db->query('ROLLBACK TO SAVEPOINT ' . self::currentSavepointName()); if ($result) { self::$openTransactionsCount--; } } else { // Just to be sure throw new TipyDaoException('Negative open transactions counter. Please contact tipy maintainers'); } return $result; }
/** * Run tests * * Returns exit status: * * - 0 - all tests passed * - 1 - there were errors or failures * * @return integer */ public function run() { $this->findFixtures(); $app = TipyApp::getInstance(); $app->connectToDb(); $app->db->query('DROP DATABASE IF EXISTS ' . $app->config->get('db_test_name')); $app->db->query('CREATE DATABASE ' . $app->config->get('db_test_name')); $app->db->select_db($app->config->get('db_test_name')); foreach ($this->fixtureFiles as $fixture) { TipyTestCase::applyFixture($app->db, $fixture); } $this->requireAutoloads(); echo PHP_EOL; foreach ($this->testNames as $test) { require_once $this->testFiles[$test]; $test = new $test(); $test->run(); $this->updateSummary($test->getSummary()); // Force to call __destruct() unset($test); } $this->printSummary(); if (sizeof($this->failures) + sizeof($this->exceptions) == 0) { return 0; } else { return 1; } }
/** * Get application instance * * Contruct application if it has not been initialized yet. * * **NOTE** Does not connect to database. * * @return TipyApp * @see TipyApp::connectToDb() */ public static function getInstance() { if (null === self::$instance) { self::$instance = new self(); } return self::$instance; }