Exemple #1
0
 /**
  * @param BaseTestCase $testCase
  * @param array $output
  * @param int $statusCode
  * @return Command A stub configured with $output and $statuCode
  */
 public static function withStubbedResult(BaseTestCase $testCase, $output, $statusCode)
 {
     $resultStub = new StubbedCommandResult($output, $statusCode);
     return $testCase->shmock('Bart\\Shell\\Command', function ($cmd) use($resultStub) {
         $cmd->disable_original_constructor();
         $cmd->getResult()->once()->return_value($resultStub);
     });
 }
Exemple #2
0
 public function setUp()
 {
     parent::setUp();
     $this->head = CommitTest::getStubCommit($this, $this->commitHash, function ($commit) {
         $commit->gerritChangeId()->once()->return_value($this->changeId);
     });
 }
Exemple #3
0
 public function setUp()
 {
     /** @var GerritConfig $gerritConfig */
     $gerritConfigs = $this->getMock('Bart\\Configuration\\GerritConfig', array(), array(), '', false);
     $gerritConfigs->expects($this->once())->method('host')->will($this->returnValue('gerrit.example.com'));
     $gerritConfigs->expects($this->once())->method('sshPort')->will($this->returnValue(29418));
     $gerritConfigs->expects($this->once())->method('sshUser')->will($this->returnValue('gerrit'));
     $gerritConfigs->expects($this->once())->method('sshKeyFile')->will($this->returnValue('~/.ssh/keyFile'));
     $this->gerritConfigs = $gerritConfigs;
     parent::setUp();
 }
 /**
  * @internal
  * For an instance of a Configuration class, execute each of its get methods and
  * assert they each return a non-empty value
  * @param Configuration $configs The instantiated instance, e.g. new GitHookConfig($commit)
  * @param BaseTestCase $phpu
  * @param string $configurationClassName
  */
 public static function assertConfigurationGetters(Configuration $configs, BaseTestCase $phpu, $configurationClassName)
 {
     $logger = \Logger::getLogger(__CLASS__);
     $reflect = new \ReflectionClass($configurationClassName);
     $methods = $reflect->getMethods(\ReflectionMethod::IS_PUBLIC);
     $logger->debug("Iterating over relevant methods for {$configurationClassName}");
     foreach ($methods as $method) {
         if ($method->isStatic()) {
             continue;
         }
         if ($method->isConstructor()) {
             continue;
         }
         $logger->debug("Calling {$method->getName()} for {$configurationClassName}");
         $methodName = $method->getName();
         // Let's call the method! E.g. $gerritConfig::sshUser()
         $phpu->assertNotEmpty($configs->{$methodName}(), "{$methodName}()");
     }
 }
Exemple #5
0
 /**
  * Utility method to create a stub Commit for any tests that need one
  * Custom expectations can be set via the $configure parameter
  * @param BaseTestCase $phpu
  * @param string $revision
  * @param callable $configure Shmock configuration function
  * @return Commit
  */
 public static function getStubCommit(BaseTestCase $phpu, $revision = 'HEAD', callable $configure = null)
 {
     return $phpu->shmock('\\Bart\\Git\\Commit', function ($commit) use($revision, $configure) {
         $commit->disable_original_constructor();
         $commit->__toString()->any()->return_value($revision);
         $commit->revision()->any()->return_value($revision);
         if ($configure) {
             $configure($commit);
         }
     });
 }
 /**
  * Verify All requests were executed
  */
 public function verify()
 {
     $this->phpu->assertEmpty($this->invocations, "StrictReturnValueMap Error: Not all requests were completed");
 }
Exemple #7
0
 public static function assertREADME(BaseTestCase $phpu, $configurationClassName, $configFileName)
 {
     $phpu->shmockAndDieselify('\\Bart\\Shell', function ($shell) {
         $shell->std_in_secret()->any()->return_value('secret');
         $shell->std_in()->any()->return_value('secret');
     });
     $phpu->doStuffWithTempDir(function (BaseTestCase $phpu, $dirName) use($configurationClassName, $configFileName) {
         $logger = \Logger::getLogger(__CLASS__);
         $logger->debug("Starting README test for {$configurationClassName}");
         $readme = TestConfigurationsHelper::getReadme($phpu, $configurationClassName);
         file_put_contents("{$dirName}/{$configFileName}", $readme);
         // Reset the cache so that the configs will be read from disk
         $logger->debug("Configuring system to load configs from {$dirName}");
         TestConfigurationsHelper::reset($dirName);
         $configs = new $configurationClassName();
         TestConfigurationsHelper::assertConfigurationGetters($configs, $phpu, $configurationClassName);
     });
 }
Exemple #8
0
 public function setUp()
 {
     parent::setUp();
     putenv('GITOSIS_USER='******'abcde123', 'bart.git');
 }
Exemple #9
0
 public function setUp()
 {
     $this->opts = array('wsdl' => 'some random path', 'key' => 'val');
     $this->soap = $this->getMock('\\SoapClient', array(), array(), '', false);
     parent::setUp();
 }
Exemple #10
0
 public function setUp()
 {
     parent::setUp();
     $this->stubConfigs();
 }