Example #1
0
 public function testAddItemInInnerScope()
 {
     $this->context->push();
     $this->context->set('test', 'test');
     $this->assertEquals('test', $this->context->get('test'));
     $this->context->pop();
     $this->assertEquals(null, $this->context->get('test'));
 }
Example #2
0
 public function test_stack()
 {
     $context = new Context();
     $this->assertSame([], $context->to_array());
     $context->push();
     $context['one'] = 1;
     $this->assertSame(['one' => 1], $context->to_array());
     $context->push();
     $context['two'] = 2;
     $this->assertSame(['one' => 1, 'two' => 2], $context->to_array());
     $context->push();
     $context['three'] = 3;
     $this->assertSame(['one' => 1, 'two' => 2, 'three' => 3], $context->to_array());
     $context->pop();
     $this->assertSame(['one' => 1, 'two' => 2], $context->to_array());
     $context->pop();
     $this->assertSame(['one' => 1], $context->to_array());
     $context->pop();
     $this->assertSame([], $context->to_array());
 }
Example #3
0
 public function test_context()
 {
     $c = new Context(array('a' => 1, 'b' => 'xyzzy'));
     $this->assertEquals($c['a'], 1);
     $this->assertEquals($c->push(), array());
     $c['a'] = 2;
     $this->assertEquals($c['a'], 2);
     $this->assertEquals($c->get('a'), 2);
     $this->assertEquals($c->pop(), array('a' => 2));
     $this->assertEquals($c['a'], 1);
     $this->assertEquals($c->get('foo', 42), 42);
 }
Example #4
0
 public function testContext()
 {
     $server = $this->getMockBuilder('Deployer\\Server\\ServerInterface')->disableOriginalConstructor()->getMock();
     $env = $this->getMockBuilder('Deployer\\Server\\Environment')->disableOriginalConstructor()->getMock();
     $input = $this->getMockBuilder('Symfony\\Component\\Console\\Input\\InputInterface')->disableOriginalConstructor()->getMock();
     $output = $this->getMockBuilder('Symfony\\Component\\Console\\Output\\OutputInterface')->disableOriginalConstructor()->getMock();
     $context = new Context($server, $env, $input, $output);
     $this->assertInstanceOf('Deployer\\Server\\ServerInterface', $context->getServer());
     $this->assertInstanceOf('Deployer\\Server\\Environment', $context->getEnvironment());
     $this->assertInstanceOf('Symfony\\Component\\Console\\Input\\InputInterface', $context->getInput());
     $this->assertInstanceOf('Symfony\\Component\\Console\\Output\\OutputInterface', $context->getOutput());
     Context::push($context);
     $this->assertEquals($context, Context::get());
     $this->assertEquals($context, Context::pop());
 }
Example #5
0
 /**
  * Run task.
  *
  * @param Context $context
  */
 public function run(Context $context)
 {
     Context::push($context);
     $env = $context->getEnvironment();
     // Save cd's working_path path.
     if ($env !== null) {
         $workingPath = $env->get('working_path', false);
     }
     // Call tasks.
     call_user_func($this->callback);
     // Restore cd's working_path path.
     if ($env !== null && isset($workingPath)) {
         $env->set('working_path', $workingPath);
     }
     Context::pop();
 }
Example #6
0
 public function testContainsTellsYouIfAGivenContextIsInTheCurrentStack()
 {
     $context = new Context();
     $context->push('foo');
     $context->push('bar');
     $context->push('baz');
     $this->assertTrue($context->contains('foo'));
     $this->assertTrue($context->contains('bar'));
     $this->assertTrue($context->contains('baz'));
     $popped = $context->pop();
     $this->assertFalse($context->contains($popped));
     // TODO: remove once global state is fully deprecated (2.0)
     _elgg_services()->setValue('context', new Context());
     elgg_push_context('foo');
     elgg_push_context('bar');
     elgg_push_context('baz');
     $this->assertTrue(elgg_in_context('foo'));
     $this->assertTrue(elgg_in_context('bar'));
     $this->assertTrue(elgg_in_context('baz'));
     $popped = elgg_pop_context();
     $this->assertFalse(elgg_in_context($popped));
 }
Example #7
0
 public function testFailToSetEmptyContext()
 {
     $context = new Context();
     $context->set("  ");
     $this->assertNull($context->peek());
     $this->assertNull($context->pop());
     $context->push("  ");
     $this->assertEquals("  ", $context->peek());
     $this->assertEquals("  ", $context->pop());
 }