本文整理汇总了PHP中Env::push方法的典型用法代码示例。如果您正苦于以下问题:PHP Env::push方法的具体用法?PHP Env::push怎么用?PHP Env::push使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Env
的用法示例。
在下文中一共展示了Env::push方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: catch
try {
Env::get('_test_foo');
$this->assert(false, 'Exception accessing unknown Env value');
} catch (\Exception $e) {
$this->assert(true, 'Exception accessing unknown Env value');
}
Env::set('_test_foo', 'bar');
$this->assertEqual(Env::get('_test_foo'), 'bar', 'Read Env value');
Env::set('_test_foo', 'a', 10);
$this->assertEqual(Env::get('_test_foo'), 'a', 'Apply higher priority value');
Env::set('_test_foo', 'b', -5);
$this->assertEqual(Env::get('_test_foo'), 'a', 'Ignore low priority value');
Env::push('_test_foo', 'c');
$this->assertEqual(Env::get('_test_foo'), 'c', 'Push env value');
Env::push('_test_foo', 'd');
$this->assertEqual(Env::get('_test_foo'), 'd', 'Push another env value');
Env::pop('_test_foo');
$this->assertEqual(Env::get('_test_foo'), 'c', 'Pop env value');
Env::pop('_test_foo');
$this->assertEqual(Env::get('_test_foo'), 'a', 'Pop another env value');
try {
Env::pop('_test_foo');
$this->assert(false, 'Exception popping too many times');
} catch (\Exception $e) {
$this->assert(true, 'Exception popping too many times');
}
try {
Env::pop('_test_bar', 'c');
$this->assert(false, 'Exception popping unknown Env value');
} catch (\Exception $e) {
示例2: ScheduledTaskController
<?php
namespace Fierce;
$db = $this->mock('DB');
Env::push('db', $db);
$db->ScheduledTask = $this->mock('DBEntity', 'ScheduledTask');
$taskController = new ScheduledTaskController();
$taskController->db = $db;
// check if a scheduled task runs properly
$task = (object) ['id' => '63E3BACB-3F7B-4C77-A303-F03FB2EE117C', 'status' => 'pending', 'date' => new \DateTime(), 'repeat' => null, 'class' => 'Fierce\\Test\\DummyTask', 'method' => 'run', 'log' => null];
$db->ScheduledTask->prepareForCall('find', null, [$task]);
$db->ScheduledTask->prepareForCall('byId', null, $task);
$activeWrite = null;
$completeWrite = null;
$db->ScheduledTask->prepareForCall('write', null, function ($id, $row, $allowOverwrite) use(&$activeWrite, &$completeWrite) {
if ($row->status == 'active') {
$activeWrite = $row;
return;
}
if ($row->status == 'complete') {
$completeWrite = $row;
return;
}
});
$taskController->defaultAction();
$this->assert($activeWrite != null, 'Task marked active');
$log = json_decode($activeWrite->log);
$logEntry = $log[0];
$this->assert((new \DateTime())->getTimestamp() - (new \DateTime($logEntry->started))->getTimestamp() >= 0 && (new \DateTime())->getTimestamp() - (new \DateTime($logEntry->started))->getTimestamp() < 10, 'Active task included a valid start date');
$log = json_decode($completeWrite->log);