/**
  * Get stub templates.
  *
  * @return string
  */
 public function getStub()
 {
     $parser = $this->getNameParser();
     if ($parser->isCreate()) {
         return Stub::createFromPath(__DIR__ . '/Stubs/migration/create.stub', ['class' => $this->getClass(), 'table' => $parser->getTable(), 'fields' => $this->getSchemaParser()->render()]);
     } elseif ($parser->isAdd()) {
         return Stub::createFromPath(__DIR__ . '/Stubs/migration/add.stub', ['class' => $this->getClass(), 'table' => $parser->getTable(), 'fields_up' => $this->getSchemaParser()->up(), 'fields_down' => $this->getSchemaParser()->down()]);
     } elseif ($parser->isDelete()) {
         return Stub::createFromPath(__DIR__ . '/Stubs/migration/delete.stub', ['class' => $this->getClass(), 'table' => $parser->getTable(), 'fields_down' => $this->getSchemaParser()->up(), 'fields_up' => $this->getSchemaParser()->down()]);
     } elseif ($parser->isDrop()) {
         return Stub::createFromPath(__DIR__ . '/Stubs/migration/drop.stub', ['class' => $this->getClass(), 'table' => $parser->getTable(), 'fields' => $this->getSchemaParser()->render()]);
     }
     return parent::getStub();
 }
Beispiel #2
0
 /**
  * @expectedException \PhpDeal\Exception\ContractViolation
  */
 public function testInvariantViolatedAfterSeveralMethods()
 {
     $this->stub->accelerate(10, 30);
     // let's have a speed 300m/s
     $this->stub->decelerate(20, 20);
     // Negative speed?
 }
 public function testMatches()
 {
     $repo = $this->getRepo('foobar');
     $criterion = new Stub(false);
     $this->assertFalse($criterion->matches($repo));
     $criterion = new Stub(true);
     $this->assertTrue($criterion->matches($repo));
 }
Beispiel #4
0
Datei: stub.php Projekt: jasny/Q
function useStub()
{
    $a = new Stub();
    $info = array('test');
    for ($i = 0; $i < LOOP; $i++) {
        $a->doIt($info);
    }
}
 /**
  * Get Json Stub.
  *
  * @param Stub $stub
  *
  * @return array
  */
 protected function getJsonStub(Stub $stub)
 {
     $jsonResponses = [];
     $jsonPredicates = [];
     /** @var Response $response */
     foreach ($stub->getResponses() as $response) {
         $jsonResponses[] = $response->getJsonDefinition();
     }
     /** @var Predicate $response */
     foreach ($stub->getPredicates() as $predicate) {
         $jsonPredicates[] = $predicate->getJsonDefinition();
     }
     return ['responses' => $jsonResponses, 'predicates' => $jsonPredicates];
 }
Beispiel #6
0
 public function setUp()
 {
     parent::setUp();
     $resolver = M::mock('Illuminate\\Database\\ConnectionResolverInterface');
     $resolver->shouldReceive('connection')->andReturn($this->getConnectionWithConfig('default'));
     Stub::setConnectionResolver($resolver);
 }
 public function test_session_to_user_likes_convert()
 {
     $helper = new \Sugar\Favorites\Helper();
     $stub = Stub::create(['name' => 123]);
     $stub->like('user_1', false);
     $stub->like('session_1', true);
     $helper->convertSessionToUserLikes('session_1', 'user_1');
     $this->assertEquals(1, $stub->likeCount);
 }
Beispiel #8
0
 public function locate_plugins()
 {
     $plugins = array();
     foreach ($this->plugin_paths() as $pp) {
         foreach (glob($pp . '/*', GLOB_ONLYDIR) as $dir) {
             if (Utils::is_plugin($dir)) {
                 try {
                     $stub = new Stub($dir);
                     $plugins[$stub->id()] = $stub;
                 } catch (InvalidPluginException $ipe) {
                     // just swallow it
                     // we're only interested in locating valid plugins,
                     // not dealing with broken ones.
                 }
             }
         }
     }
     return $plugins;
 }
Beispiel #9
0
 /**
  * Get stub template for generated file.
  *
  * @return string
  */
 public function getStub()
 {
     if ($this->plain) {
         return $this->getPath();
     }
     if ($template = $this->template) {
         return Stub::create($template, $this->getReplacements())->render();
     }
     return parent::getStub();
 }
 public function test_rebuild_test()
 {
     $stub1 = Stub::create(['name' => 456]);
     $stub2 = Stub::create(['name' => 123]);
     $stub1->like('like', 1);
     $stub1->like('like', 7);
     $stub1->like('like', 8);
     $stub2->like('like', 1);
     $stub2->like('like', 2);
     $stub2->like('like', 3);
     $stub2->like('like', 4);
     LikeCounter::truncate();
     LikeCounter::rebuild('Stub');
     $results = LikeCounter::all();
     $this->assertEquals(2, $results->count());
 }
Beispiel #11
0
 public function getResultOfCall()
 {
     if (is_null($this->times)) {
         $message = "[{$this->mockName}]\n\nMethod ({$this->methodName}) called but is expected to not be called";
         $this->log("err", $message);
         $this->errors[] = $message;
         throw new MockException($message);
     } elseif ($this->times === 0) {
         $message = "[{$this->mockName}]\n\nMethod ({$this->methodName}) expected to be called {$this->times} times but called at least one more";
         $this->log("err", $message);
         $this->errors[] = $message;
         throw new MockException($message);
     } else {
         $this->times -= 1;
         return parent::getResultOfCall();
     }
 }
Beispiel #12
0
    {
        return true;
    }
}
Stub::generate("Dummy");
Stub::generate("Dummy", "AnotherStubDummy");
Stub::generate("Dummy", "StubDummyWithExtraMethods", array("extraMethod"));
class SpecialSimpleStub extends SimpleStub
{
    function SpecialSimpleStub($wildcard)
    {
        $this->SimpleStub($wildcard);
    }
}
SimpleTestOptions::setStubBaseClass("SpecialSimpleStub");
Stub::generate("Dummy", "SpecialStubDummy");
SimpleTestOptions::setStubBaseClass("SimpleStub");
class TestOfStubGeneration extends UnitTestCase
{
    function TestOfStubGeneration()
    {
        $this->UnitTestCase();
    }
    function testCloning()
    {
        $stub =& new StubDummy($this);
        $this->assertTrue(method_exists($stub, "aMethod"));
        $this->assertNull($stub->aMethod());
    }
    function testCloningWithExtraMethod()
    {
Beispiel #13
0
    function getCountriesCollection()
    {
        return $this->countries;
    }
}
class AkTestCountry
{
    function AkTestCountry($id, $name)
    {
        $this->id = $id;
        $this->name = $name;
    }
    function getCountryId()
    {
        return $this->id;
    }
    function getCountryName()
    {
        return $this->name;
    }
}
Stub::generate('AkActiveRecord');
Stub::generate('AkActionController');
class HelpersUnitTester extends AkUnitTest
{
    function HelpersUnitTester()
    {
        $base_url = parse_url(dirname(@$_SERVER['SCRIPT_NAME']));
        $this->testing_url_path = '/' . ltrim($base_url['path'], '/');
    }
}
Beispiel #14
0
 public function testEnsureCanHandleResult()
 {
     $this->stub->returnPrivateValue();
 }
 /**
  * Get stub template for generated file.
  *
  * @return string
  */
 public function getStub()
 {
     $stub = new Stub($this->stub . '.stub', $this->getReplacements());
     $stub->setBasePath(__DIR__ . '/Stubs/');
     return $stub->render();
 }
 /**
  *    The new mock class code as a string.
  *    @param string $class           Class to clone.
  *    @param string $mock_class      New class name.
  *    @param array $methods          Additional methods.
  *    @return string                 Code for new mock class.
  *    @static
  *    @access private
  */
 function _createClassCode($class, $mock_class, $methods) {
     $mock_base = SimpleTestOptions::getMockBaseClass();
     $code = "class $mock_class extends $mock_base {\n";
     $code .= "    function $mock_class(&\$test, \$wildcard = MOCK_WILDCARD) {\n";
     $code .= "        \$this->$mock_base(\$test, \$wildcard);\n";
     $code .= "    }\n";
     $code .= Stub::_createHandlerCode($class, $mock_base, $methods);
     $code .= "}\n";
     return $code;
 }
Beispiel #17
0
 /**
  * Test exception thrown by getMailer.
  *
  * @expectedException Cake\Mailer\Exception\MissingMailerException
  * @expectedExceptionMessage Mailer class "Test" could not be found.
  */
 public function testGetMailerThrowsException()
 {
     $stub = new Stub();
     $stub->getMailer('Test');
 }
Beispiel #18
0
 /**
  * @param mixed $value
  * @dataProvider providerVerifyManyContractsInvalid
  * @expectedException \PhpDeal\Exception\ContractViolation
  */
 public function testVerifyManyContractsInvalid($value)
 {
     $this->stub->sub($value);
 }
Beispiel #19
0
 /**
  * @param int $variable
  * @dataProvider providerInvariantInvalid
  * @expectedException \PhpDeal\Exception\ContractViolation
  */
 public function testInvariantInvalid($variable)
 {
     $this->stub->setVariable($variable);
 }
Beispiel #20
0
 /**
  * @param int $parameter
  * @dataProvider providerVerifyValid
  */
 public function testVerifyValid($parameter)
 {
     $this->stub->add($parameter);
 }
Beispiel #21
0
                    $params[] = $param;
                }
            }
            $func[] = $method->getName() . '(' . implode(', ', $params) . ')';
            $doc[] = "\t */\n";
            $func[] = "\n\t{}\n";
            $output .= implode("\n", $doc);
            $output .= "\t" . implode(' ', $func) . "\n";
        }
        return $output;
    }
    /**
     * @param string $dir
     */
    protected function _cleanup($dir)
    {
        $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($dir), \RecursiveIteratorIterator::CHILD_FIRST);
        foreach ($iterator as $path) {
            if ($path->isDir() && !in_array($path->getFileName(), array('.', '..'))) {
                rmdir($path->getPathName());
            } else {
                if ($path->isFile() && !in_array($path->getFileName(), array('.', '..'))) {
                    unlink($path->getPathName());
                }
            }
        }
        rmdir($dir);
    }
}
$s = new Stub('phalcon', __DIR__ . '/../../../ide/phpstorm');
$s->generate();
Beispiel #22
0
    var $last_name = array('Silva', 'Santos', 'Oliveira', 'Shultz', 'Cordeiro');
    var $titles = array('Coronel', 'Doutor', 'Desembargador', 'Brigadeiro');
    function generate_number()
    {
        return mt_rand(0, 1000);
    }
    function generate_name()
    {
        shuffle($this->first_name);
        shuffle($this->last_name);
        $indice_fn = mt_rand(0, count($this->first_name) - 1);
        $indice_ln = mt_rand(0, count($this->last_name) - 1);
        return $this->first_name[$indice_fn] . ' ' . $this->last_name[$indice_ln];
    }
    function generate_address()
    {
        shuffle($this->titles);
        shuffle($this->first_name);
        shuffle($this->last_name);
        $indice_fn = mt_rand(0, count($this->first_name) - 1);
        $indice_ln = mt_rand(0, count($this->last_name) - 1);
        $indice_tt = mt_rand(0, count($this->titles) - 1);
        return $this->titles[$indice_tt] . ' ' . $this->first_name[$indice_fn] . ' ' . $this->last_name[$indice_ln];
    }
}
$stub = new Stub();
echo $stub->generate_name();
echo ' - ';
echo $stub->generate_address();
echo ', ';
echo $stub->generate_number();
Beispiel #23
0
    {
        return true;
    }
}
Stub::generate('Dummy', 'StubDummy');
Stub::generate('Dummy', 'AnotherStubDummy');
Stub::generate('Dummy', 'StubDummyWithExtraMethods', array('extraMethod'));
class SpecialSimpleStub extends SimpleMock
{
    function SpecialSimpleStub()
    {
        $this->SimpleMock();
    }
}
SimpleTest::setMockBaseClass('SpecialSimpleStub');
Stub::generate('Dummy', 'SpecialStubDummy');
SimpleTest::setMockBaseClass('SimpleMock');
class TestOfStubGeneration extends UnitTestCase
{
    function testCloning()
    {
        $stub =& new StubDummy();
        $this->assertTrue(method_exists($stub, "aMethod"));
        $this->assertNull($stub->aMethod(null));
    }
    function testCloningWithExtraMethod()
    {
        $stub =& new StubDummyWithExtraMethods();
        $this->assertTrue(method_exists($stub, "extraMethod"));
    }
    function testCloningWithChosenClassName()
Beispiel #24
0
 /**
  * @param int $variable
  * @dataProvider providerEnsureInvalid
  * @expectedException \PhpDeal\Exception\ContractViolation
  */
 public function testEnsureInvalid($variable)
 {
     $this->stub->add($variable);
 }