/** * Test basic get/set functionality. */ public function testGetSet() { $args = new Args(); $args->setArg('key', 'value'); $this->assertSame('value', $args->getArg('key')); $args->setArgs(['foo']); $this->assertSame(['foo'], $args->getArgs()); $args->setCommand('cmd'); $this->assertSame('cmd', $args->getCommand()); $args->setMeta('meta', 123); $this->assertSame(123, $args->getMeta('meta')); $this->assertSame('default', $args->getMeta('nex', 'default')); $args->setOpt('grim', 567); $this->assertSame(567, $args->getOpt('grim')); $args->setOpts(['opt' => 'value']); $this->assertSame(['opt' => 'value'], $args->getOpts()); $args->setOpt('opt', null); $this->assertSame([], $args->getOpts()); $args['foo'] = 'bar'; $this->assertTrue(isset($args['foo'])); $this->assertSame('bar', $args['foo']); $this->assertSame('bar', $args->getOpt('foo')); unset($args['foo']); $this->assertNull($args['foo']); }
protected function mergeIntoCommand(Args $args) { $target = $args->getArg('target'); if (!static::git_branch_exists($target)) { throw new \RuntimeException("Target branch {$target} does not exist", -1); } $dirty = null; $branch = static::git_current_branch($dirty); static::write_ln("Current branch: {$branch}"); if ($dirty) { static::write_ln("You have uncommitted work !"); static::write($dirty); static::write_ln('---'); } $text = static::read_text('Enter a merge description', ''); $texts = ['commit' => $text, 'merge' => $text ? "Merge {$branch}: {$text}" : '', 'mergeback' => "Merge {$target}"]; foreach ($texts as &$text) { $text = "-m \"{$text}\""; } static::write_ln(); if ($dirty) { static::write_ln("# You should commit your work :"); static::write_ln("git add -A"); static::write_ln("git commit -a {$texts['commit']}"); } if ($args->getOpt('paranoid')) { if ($target == $this->config['develop_branch'] || $target == $this->config['master_branch']) { static::write_ln("# We will pull and merge {$target} before all"); static::write_ln("git checkout {$target}"); static::write_ln("git pull"); static::write_ln("git checkout {$branch}"); static::write_ln("git merge --no-ff {$target} {$texts['mergeback']}"); } } static::write_ln("# Checkout the target branch {$target} :"); static::write_ln("git checkout {$target}"); if ($target == $this->config['develop_branch'] || $target == $this->config['master_branch']) { static::write_ln("# You may want to pull {$target} :"); static::write_ln("git pull"); } static::write_ln("# Merge {$branch} into {$target} :"); static::write_ln("git merge --no-ff {$branch} {$texts['merge']}"); if ($target == $this->config['develop_branch'] || $target == $this->config['master_branch']) { static::write_ln("# You may want to push {$target} :"); static::write_ln("git push"); } static::write_ln("# Go back to your working branch {$branch} :"); static::write_ln("git checkout {$branch}"); if ($target == $this->config['develop_branch'] || $target == $this->config['master_branch']) { static::write_ln("# At some point you may want to keep your working branch up-to-date :"); static::write_ln("git merge --no-ff {$target} {$texts['mergeback']}"); } static::write_ln(); if ($target == $this->config['master_branch']) { static::write_ln("# WARNING: merging to {$target} should be done with caution."); static::write_ln("# You should use the bump command."); static::write_ln(); } $this->disclaimer(); }