public function test_can_get_all_permissions()
 {
     $this->config->shouldReceive('get')->with('acl.permissions.list', [])->once()->andReturn(['mocked']);
     $permissions = $this->driver->getAllPermissions();
     $this->assertInstanceOf(Collection::class, $permissions);
     $this->assertTrue($permissions->contains('mocked'));
 }
 public function test_doesnt_have_column()
 {
     $table = m::mock(\Doctrine\DBAL\Schema\Table::class);
     $this->schema->shouldReceive('getTable')->with('table_name')->once()->andReturn($table);
     $table->shouldReceive('getColumns')->once()->andReturn(['column' => 'instance']);
     $this->assertFalse($this->builder->hasColumns('table_name', ['column2']));
 }
Exemple #3
0
 /** @test */
 public function it_gets_alerts_by_type()
 {
     $type = Augstudios\Alerts\AlertType::Info;
     $this->store->shouldReceive('priorOfType')->with($type)->andReturn(Illuminate\Support\Collection::make());
     $result = $this->alerts->ofType($type);
     $this->assertInstanceOf('Illuminate\\Support\\Collection', $result);
 }
 public function testMultiLevelDemeterChain()
 {
     $this->mock->shouldReceive('levelOne->levelTwo->getFirst')->andReturn('first');
     $this->mock->shouldReceive('levelOne->levelTwo->getSecond')->andReturn('second');
     $this->assertEquals('second', $this->mock->levelOne()->levelTwo()->getSecond());
     $this->assertEquals('first', $this->mock->levelOne()->levelTwo()->getFirst());
 }
 public function test_throw_exception_when_no_version()
 {
     $this->configuration->shouldReceive('resolveVersionAlias')->andReturn(null);
     $this->configuration->shouldReceive('getMigratedVersions')->andReturn(['version1']);
     $this->configuration->shouldReceive('getAvailableVersions')->andReturn(['version1']);
     $this->setExpectedException(MigrationVersionException::class);
     $migration = new Migration($this->configuration, 'latest');
 }
 protected function setUp()
 {
     $this->generator = new MigrationFileGenerator(new StubLocator(), new VariableReplacer(), new FileWriter());
     $this->configuration = m::mock(Configuration::class);
     $this->configuration->shouldReceive('getMigrationsNamespace')->andReturn('Database\\Migrations');
     $this->configuration->shouldReceive('getMigrationsDirectory')->andReturn(__DIR__ . '/../stubs/migrations');
     $this->configuration->shouldReceive('getNamingStrategy')->andReturn(new DefaultNamingStrategy());
 }
 public function test_migrate()
 {
     $this->migration->shouldReceive('getMigration')->andReturn($this->dbalMig);
     $this->migration->shouldReceive('getConfiguration')->andReturn($this->configuration);
     $this->configuration->shouldReceive('getVersion')->andReturn(m::mock(Version::class));
     $this->migration->shouldReceive('getVersion')->andReturn('version1');
     $this->dbalMig->shouldReceive('migrate')->with('version1', false, false)->andReturn(['version1' => 'SQL']);
     $migrator = new Migrator();
     $migrator->migrate($this->migration);
     $this->assertContains('<info>Migrated:</info> version1', $migrator->getNotes());
 }
Exemple #8
0
 /**
  * Calls mock method if its have expectations. Calls parent method otherwise
  *
  * @param string $method
  * @param array  $arguments Arguments to pass in method call
  *
  * @return  mixed See parent implementation
  */
 protected static function callMockOrParent($method, array $arguments)
 {
     $classToCall = 'parent';
     if (static::$mock && static::$mock->mockery_getExpectationsFor($method)) {
         $classToCall = static::$mock;
     }
     return call_user_func_array(array($classToCall, $method), $arguments);
 }
 public function test_can_make_configuration()
 {
     $this->connection->shouldReceive('getConfiguration')->andReturn($this->configuration);
     $this->config->shouldReceive('get')->once()->with('migrations.name', 'Doctrine Migrations')->andReturn('Doctrine Migrations');
     $this->config->shouldReceive('get')->once()->with('migrations.namespace', 'Database\\Migrations')->andReturn('Database\\Migrations');
     $this->config->shouldReceive('get')->once()->with('migrations.table', 'migrations')->andReturn('migrations');
     $this->config->shouldReceive('get')->once()->with('migrations.schema.filter', '/^(?).*$/')->andReturn('migrations');
     $this->configuration->shouldReceive('setFilterSchemaAssetsExpression')->with('/^(?).*$/')->once();
     $this->config->shouldReceive('get')->once()->with('migrations.naming_strategy', DefaultNamingStrategy::class)->andReturn(DefaultNamingStrategy::class);
     $this->container->shouldReceive('make')->with(DefaultNamingStrategy::class)->once()->andReturn(new DefaultNamingStrategy());
     $this->config->shouldReceive('get')->once()->with('migrations.directory', database_path('migrations'))->andReturn(database_path('migrations'));
     $configuration = $this->factory->make($this->connection);
     $this->assertInstanceOf(Configuration::class, $configuration);
     $this->assertEquals('Doctrine Migrations', $configuration->getName());
     $this->assertEquals('Database\\Migrations', $configuration->getMigrationsNamespace());
     $this->assertEquals('migrations', $configuration->getMigrationsTableName());
     $this->assertInstanceOf(DefaultNamingStrategy::class, $configuration->getNamingStrategy());
     $this->assertEquals(database_path('migrations'), $configuration->getMigrationsDirectory());
 }
 public function test_can_get_all_permissions()
 {
     $this->config->shouldReceive('get')->with('acl.permissions.entity')->once()->andReturn(Permission::class);
     $this->registry->shouldReceive('getManagerForClass')->with(Permission::class)->once()->andReturn($this->em);
     $this->em->shouldReceive('getUnitOfWork')->once()->andReturn($this->em);
     $this->em->shouldReceive('getEntityPersister')->with(Permission::class)->once()->andReturn($this->em);
     $this->em->shouldReceive('loadAll')->once()->andReturn([new Permission('mocked')]);
     $meta = new ClassMetadata(Permission::class);
     $meta->table = ['name' => 'permissions'];
     $this->em->shouldReceive('getClassMetadata')->once()->andReturn($meta);
     $connection = m::mock(Connection::class);
     $this->em->shouldReceive('getConnection')->once()->andReturn($connection);
     $schema = m::mock(MySqlSchemaManager::class);
     $connection->shouldReceive('getSchemaManager')->once()->andReturn($schema);
     $schema->shouldReceive('tablesExist')->with(['permissions'])->andReturn(true);
     $permissions = $this->driver->getAllPermissions();
     $this->assertInstanceOf(Collection::class, $permissions);
     $this->assertTrue($permissions->contains('mocked'));
 }
 public function test_can_build_down_sql()
 {
     $this->from->shouldReceive('getMigrateFromSql')->with($this->to, $this->platform)->andReturn(['QUERY3', 'QUERY4']);
     $sql = $this->builder->down($this->configuration, $this->from, $this->to);
     $this->assertEquals(trim(file_get_contents(__DIR__ . '/../stubs/down.stub')), $sql);
 }
Exemple #12
0
 /**
  * Generates a new mock object for this container
  *
  * I apologies in advance for this. A God Method just fits the API which
  * doesn't require differentiating between classes, interfaces, abstracts,
  * names or partials - just so long as it's something that can be mocked.
  * I'll refactor it one day so it's easier to follow.
  *
  * @return \Mockery\Mock
  */
 public function mock()
 {
     $class = null;
     $name = null;
     $partial = null;
     $expectationClosure = null;
     $quickdefs = array();
     $blocks = array();
     $makeInstanceMock = false;
     $args = func_get_args();
     $partialMethods = array();
     if (count($args) > 1) {
         $finalArg = end($args);
         reset($args);
         if (is_callable($finalArg)) {
             $expectationClosure = array_pop($args);
         }
     }
     while (count($args) > 0) {
         $arg = current($args);
         // check for multiple interfaces
         if (is_string($arg) && strpos($arg, ',') && !strpos($arg, ']')) {
             $interfaces = explode(',', str_replace(' ', '', $arg));
             foreach ($interfaces as $i) {
                 if (!interface_exists($i, true) && !class_exists($i, true)) {
                     throw new \Mockery\Exception('Class name follows the format for defining multiple' . ' interfaces, however one or more of the interfaces' . ' do not exist or are not included, or the base class' . ' (optional) does not exist');
                 }
             }
             $class = $interfaces;
             array_shift($args);
         } elseif (is_string($arg) && substr($arg, 0, 6) == 'alias:') {
             $class = 'stdClass';
             $name = array_shift($args);
             $name = str_replace('alias:', '', $name);
         } elseif (is_string($arg) && substr($arg, 0, 9) == 'overload:') {
             $class = 'stdClass';
             $name = array_shift($args);
             $name = str_replace('overload:', '', $name);
             $makeInstanceMock = true;
         } elseif (is_string($arg) && substr($arg, strlen($arg) - 1, 1) == ']') {
             $parts = explode('[', $arg);
             if (!class_exists($parts[0], true) && !interface_exists($parts[0], true)) {
                 throw new \Mockery\Exception('Can only create a partial mock from' . ' an existing class or interface');
             }
             $class = $parts[0];
             $parts[1] = str_replace(' ', '', $parts[1]);
             $partialMethods = explode(',', strtolower(rtrim($parts[1], ']')));
             array_shift($args);
         } elseif (is_string($arg) && (class_exists($arg, true) || interface_exists($arg, true))) {
             $class = array_shift($args);
         } elseif (is_string($arg)) {
             $name = array_shift($args);
         } elseif (is_object($arg)) {
             $partial = array_shift($args);
         } elseif (is_array($arg)) {
             if (array_key_exists(self::BLOCKS, $arg)) {
                 $blocks = $arg[self::BLOCKS];
             }
             unset($arg[self::BLOCKS]);
             $quickdefs = array_shift($args);
         } else {
             throw new \Mockery\Exception('Unable to parse arguments sent to ' . get_class($this) . '::mock()');
         }
     }
     if (!is_null($name) && !is_null($class)) {
         if (!$makeInstanceMock) {
             $mockName = \Mockery\Generator::createClassMock($class);
         } else {
             $mockName = \Mockery\Generator::createClassMock($class, null, null, array(), true);
         }
         $result = class_alias($mockName, $name);
         $mock = $this->_getInstance($name);
         $mock->mockery_init($class, $this);
     } elseif (!is_null($name)) {
         $mock = new \Mockery\Mock();
         $mock->mockery_init($name, $this);
     } elseif (!is_null($class)) {
         $mockName = \Mockery\Generator::createClassMock($class, null, null, array(), false, $partialMethods);
         $mock = $this->_getInstance($mockName);
         $mock->mockery_init($class, $this);
     } elseif (!is_null($partial)) {
         $mockName = \Mockery\Generator::createClassMock(get_class($partial), null, true, $blocks);
         $mock = $this->_getInstance($mockName);
         $mock->mockery_init(get_class($partial), $this, $partial);
     } else {
         $mock = new \Mockery\Mock();
         $mock->mockery_init('unknown', $this);
     }
     if (!empty($quickdefs)) {
         $mock->shouldReceive($quickdefs);
     }
     if (!empty($expectationClosure)) {
         $expectationClosure($mock);
     }
     $this->rememberMock($mock);
     return $mock;
 }
 function testForceDeleteCallback()
 {
     $this->mock->makePartial()->shouldReceive('activity->delete')->once()->andReturn('deleted');
     $this->assertEquals("deleted", $this->observer->deleted($this->mock));
 }
 public function test_can_get_configuration_for_specific_connection()
 {
     $this->registry->shouldReceive('getConnection')->with('connection')->andReturn($this->connection);
     $this->factory->shouldReceive('make')->with($this->connection)->andReturn('configuration');
     $this->assertEquals('configuration', $this->provider->getForConnection('connection'));
 }
 public function test_drop_column()
 {
     $this->dbal->shouldReceive('dropColumn')->with('column');
     $this->table->dropColumn('column');
 }
Exemple #16
0
 /**
  * Generates a new mock object for this container
  *
  * @return \Mockery\Mock
  */
 public function mock()
 {
     $class = null;
     $name = null;
     $partial = null;
     $expectationClosure = null;
     $quickdefs = array();
     $args = func_get_args();
     if (count($args) > 1) {
         $finalArg = end($args);
         reset($args);
         if (is_callable($finalArg)) {
             $expectationClosure = array_pop($args);
         }
     }
     while (count($args) > 0) {
         $arg = current($args);
         if (is_string($arg) && (class_exists($arg, true) || interface_exists($arg, true))) {
             $class = array_shift($args);
         } elseif (is_string($arg)) {
             $name = array_shift($args);
         } elseif (is_object($arg)) {
             $partial = array_shift($args);
         } elseif (is_array($arg)) {
             $quickdefs = array_shift($args);
         } else {
             throw new \Mockery\Exception('Unable to parse arguments sent to ' . get_class($this) . '::mock()');
         }
     }
     if (!is_null($name)) {
         $mock = new \Mockery\Mock();
         $mock->mockery_init($name, $this);
     } elseif (!is_null($class)) {
         $mockName = \Mockery\Generator::createClassMock($class);
         $mock = $this->_getInstance($mockName);
         $mock->mockery_init($class, $this);
     } elseif (!is_null($partial)) {
         $mockName = \Mockery\Generator::createClassMock(get_class($partial), null, true);
         $mock = $this->_getInstance($mockName);
         $mock->mockery_init(get_class($partial), $this, $partial);
     } else {
         $mock = new \Mockery\Mock();
         $mock->mockery_init('unknown', $this);
     }
     if (!empty($quickdefs)) {
         $mock->shouldReceive($quickdefs);
     }
     if (!empty($expectationClosure)) {
         $expectationClosure($mock);
     }
     $this->rememberMock($mock);
     return $mock;
 }
 /**
  * @test
  */
 public function convertIdValueToIntValue()
 {
     $id = $this->idWorker->generate();
     $intValue = $this->idWorker->write($id);
     $this->assertEquals($id, $this->idWorker->read($intValue));
 }
 public function test_it_calls_singleton_in_register_method()
 {
     $this->appMock->shouldReceive('singleton')->once();
     $this->provider->register();
 }