/** * Test a failing deactivate * * @return void * @author Dan Cox */ public function test_deactivateFail() { $this->modules->shouldReceive('deactivate')->with('test')->andThrow("Exception"); $CT = new CommandTester($this->command); $CT->execute(['command' => $this->command->getName(), 'name' => 'test']); $this->assertContains('Failed to deactivate', $CT->getDisplay()); }
/** * Test updating existing projects * * @return void * @author Dan Cox */ public function test_updateProjectsFromScan() { $this->DI->addMock('finder', $this->finder); $this->DI->addMock('config', $this->config); $this->DI->addMock('database', $this->database); $this->finder->shouldReceive('files')->andReturn($this->finder); $this->finder->shouldReceive('in')->andReturn([$this->finder]); $this->finder->shouldReceive('getRealPath')->andReturn('/var/www/test/test.yml'); $this->config->shouldReceive('load')->with('/var/www/test/test.yml')->andReturn($this->config); $this->config->shouldReceive('params')->andReturn($this->config); $this->config->name = 'project'; $this->config->description = ''; $this->config->root_development = ''; $this->config->root_live = ''; $this->config->repository = array('remote_url' => ''); $this->database->shouldReceive('getEntity')->andReturn($this->database); $this->database->shouldReceive('setModel'); $this->database->shouldReceive('count')->with(['name', '=', 'project'])->andReturn(1); $this->database->shouldReceive('first')->andReturn($this->database); $this->database->repository = $this->database; $this->database->shouldReceive('save'); $CT = new CommandTester($this->command); $CT->execute(['command' => $this->command->getName()]); $this->assertContains('Successfully saved project: project', $CT->getDisplay()); $this->assertContains('Finished processing project file changes', $CT->getDisplay()); }
/** * Test a fail to make a config file for whatever reason * * @return void * @author Dan Cox */ public function test_fail() { $this->setExpectedException('RuntimeException'); $this->fs->shouldReceive('mkdir')->with(WORKBENCH . 'test')->andThrow(new Exception()); $CT = new CommandTester($this->command); $CT->execute(['command' => $this->command->getName(), 'name' => 'test']); $this->assertContains('Failed', $CT->getDisplay()); }
/** * Creates the Mockery based on the service name * * @param string $service * @return void * @author Dan Cox */ public function __construct($service) { $service = str_replace('.', '_', $service); $this->mockery = \Mockery::mock($service); // Add a call for the DI $this->mockery->shouldReceive('getDI')->andReturn($this->mockery); $this->mockery->shouldReceive('setDI')->andReturn($this->mockery); }
/** * Test when a cron cannot be found * * @return void * @author Dan Cox */ public function test_invalidCron() { $this->setExpectedException('RuntimeException'); $this->database->shouldReceive('setModel')->with('Alice\\Entity\\Cron')->andReturn($this->database); $this->database->shouldReceive('count')->andReturn(0); $CT = new CommandTester($this->command); $CT->execute(['command' => $this->command->getName(), 'name' => 'test']); }
/** * Test a fail case * * @return void * @author Dan Cox */ public function test_addFail() { $this->database->shouldReceive('setModel')->with('Alice\\Entity\\Contact')->andReturn($this->database); $this->database->shouldReceive('getEntity')->andThrow('Exception'); $CT = new CommandTester($this->command); $CT->execute(['command' => $this->command->getName(), 'first' => 'test', 'last' => 'test', 'email' => '*****@*****.**', '--phone' => '12345678910']); $this->assertContains('There was an issue', $CT->getDisplay()); }
/** * Test Creating the file first * * @return void * @author Dan Cox */ public function test_createFileFirst() { $this->fs->shouldReceive('exists')->andReturn(FALSE); $this->config->shouldReceive('create')->andReturn($this->config); $this->config->shouldReceive('params')->andReturn($this->config); $this->config->shouldReceive('save'); $this->log->write('file.yml', 'logname', array('data' => array())); }
/** * Test creating config files for the mod * * @return void * @author Dan Cox */ public function test_createConfigurationFiles() { $this->config->shouldReceive('create')->andReturn($this->config); $this->config->shouldReceive('params')->andReturn($this->config); $this->config->shouldReceive('save'); $tool = new ModuleTool(); $tool->config(['test' => 'value']); $this->assertEquals('value', $this->config->test); }
/** * Basic test * * @return void * @author Dan Cox */ public function test_update() { $this->cron->shouldReceive('updateFromDB'); $this->process->shouldReceive('build')->andReturn($this->process); $this->process->shouldReceive('getProcess')->andReturn($this->process); $this->process->shouldReceive('mustRun'); $CT = new CommandTester($this->command); $CT->execute(['command' => $this->command->getName()]); $this->assertContains('Updated', $CT->getDisplay()); }
/** * Test a run through that fails on dctrine * * @return void * @author Dan Cox */ public function test_runThroughFailDoctrine() { $this->DI->addMock('doctrineprocess', $this->doctrine); $this->doctrine->shouldReceive('build')->with(['force' => true])->andReturn($this->doctrine); $this->doctrine->shouldReceive('getProcess')->andReturn($this->doctrine); $this->doctrine->shouldReceive('mustRun')->andThrow('Exception'); $CT = new CommandTester($this->command); $CT->execute(['command' => $this->command->getName()]); $this->assertContains('Failed updating schema...', $CT->getDisplay()); }
/** * Command is simple, lets just test a run through * * @return void * @author Dan Cox */ public function test_runThrough() { $this->DI->addMock('config', $this->config); $this->config->shouldReceive('create'); $this->config->shouldReceive('params')->andReturn($this->config); $this->config->shouldReceive('save'); $CT = new CommandTester($this->command); $CT->execute(['command' => $this->command->getName(), 'name' => 'test']); $this->assertContains("Saved project file", $CT->getDisplay()); }
/** * Test a run through with a mocked process * * @return void * @author Dan Cox */ public function test_runThrough() { $this->DI->addMock('doctrineprocess', $this->doctrine); $this->doctrine->shouldReceive('build')->with(['force' => true])->andReturn($this->doctrine); $this->doctrine->shouldReceive('getProcess')->andReturn($this->doctrine); $this->doctrine->shouldReceive('run'); $this->doctrine->shouldReceive('isSuccessful')->andReturn(TRUE); $CT = new CommandTester($this->command); $CT->execute(['command' => $this->command->getName()]); $this->assertContains('Successfully updated the database schema', $CT->getDisplay()); }
/** * Test deactivating a mod * * @return void * @author Dan Cox */ public function test_deactivate() { $this->config->shouldReceive('load'); $this->probe->shouldReceive('load')->with('/var/www/'); $this->probe->shouldReceive('deactivateModule'); $this->config->shouldReceive('params')->andReturn($this->config); $this->config->modules = array('mod' => '/var/www'); $mod = new Modules(); $mod->library()->availableModules = array('mod' => '/var/www/'); $mod->deactivate('mod'); }
/** * Test updating crontab text file * * @return void * @author Dan Cox */ public function test_updateCronTabText() { $this->database->shouldReceive('setModel')->with('Alice\\Entity\\Cron')->andReturn($this->database); $this->database->shouldReceive('get')->andReturn([$this->database]); // 1 Result. $this->database->jobdate = '* * * * *'; $this->database->id = 1; $this->fs->shouldReceive('dumpFile')->with('/tmp/crontab.txt', "* * * * * /usr/bin/php " . ROOT . "alice cron:run 1\n"); $cron = new Cron(); $cron->updateFromDB(); }
/** * Test a working run through of the command * * @return void * @author Dan Cox */ public function test_runThroughCommand() { $this->command->getHelper('question')->setInputStream($this->inputStream("git init, touch readme.md\nvalue = test, foo = bar\n")); // Database expectations $this->database->shouldReceive('getEntity')->andReturn($this->database); $this->database->shouldReceive('persist'); $this->database->shouldReceive('flush'); // Mock the config class $this->DI->addMock('config', $this->config); $this->config->shouldReceive('create')->with(CONFIG . 'commands/test.command.yml'); $this->config->shouldReceive('params')->andReturn($this->config); $this->config->shouldReceive('save'); $CT = new CommandTester($this->command); $CT->execute(['command' => $this->command->getName(), 'name' => 'test.command']); }
/** * Using a test skeleton, run a basic skeleton command list * * @return void * @author Dan Cox */ public function test_runBasicSkeletonCommands() { $sp = m::mock('skeletonprocess'); $collection = m::mock('collection'); $this->DI->addMock('skeletonprocess', $sp); $this->DI->addMock('collection', $collection); $this->DI->addMock('fs', $this->filesystem); // Collection Mocks $collection->shouldReceive('create')->andReturn($collection); $collection->build_script = array('mkdir [directory]', 'composer install'); // FS Mocks $this->filesystem->shouldReceive('exists')->andReturn(TRUE); // Skeleton Mocks $sp->shouldReceive('build')->with(['directory' => __DIR__, 'verbose' => false])->andReturn($sp); $sp->shouldReceive('getProcess')->andReturn($sp); $sp->shouldReceive('setArguments')->with(array('mkdir', __DIR__))->andReturn($sp); $sp->shouldReceive('setArguments')->with(array('composer', 'install'))->andReturn($sp); $sp->shouldReceive('mustRun'); $sp->shouldReceive('getCommandLine')->andReturn("'mkdir' '" . __DIR__ . "'"); $CT = new CommandTester($this->command); $CT->execute(['command' => $this->command->getName(), 'config' => 'test.yml', 'directory' => __DIR__]); // The skeleton process passes, but the composer process fails $this->assertContains("Successfully ran command: 'mkdir'", $CT->getDisplay()); $this->assertContains("The command \"'composer'", $CT->getDisplay()); }
/** * Test the delete function * * @return void * @author Dan Cox */ public function test_removeModel() { DI::addMock('database', $this->database); $this->database->shouldReceive('getEntity')->andReturn($this->database); $this->database->shouldReceive('remove'); $this->database->shouldReceive('flush'); $this->entity->delete(); }
/** * Test that a run time exception fires when the command list does not exist * * @return void * @author Dan Cox */ public function test_runtimeExceptionOnMissingCommandList() { $this->database->shouldReceive('setModel')->with('Alice\\Entity\\Command')->andReturn($this->database); $this->database->shouldReceive('getEntity')->andReturn($this->database); $this->database->shouldReceive('count')->andReturn(0); $this->setExpectedException('RuntimeException'); $CT = new CommandTester($this->command); $CT->execute(["command" => $this->command->getName(), "name" => 'test', "time" => '* * * * *', "--commandlist" => 'test']); }
/** * Test the runtime exception fires when a command does not exist * * @return void * @author Dan Cox */ public function test_commandDoesntExist() { $this->setExpectedException('RuntimeException'); $this->database->shouldReceive('setModel')->with('Alice\\Entity\\Command')->andReturn($this->database); $this->database->shouldReceive('getEntity')->andReturn($this->database); $this->database->shouldReceive('count')->andReturn(0); $CT = new CommandTester($this->command); $CT->execute(['command' => $this->command->getName(), 'name' => 'testFail', 'directory' => __DIR__]); }
/** * Test the query builder function * * @return void * @author Dan Cox */ public function test_queryBuilder() { $connection = $this->DI->get('connection'); $connection->shouldReceive('connection')->andReturn($connection); $connection->shouldReceive('createQueryBuilder')->andReturn($this->builderStub); $this->builderStub->shouldReceive('from')->with('Test', 'u')->andReturn($this->builderStub); $this->builderStub->query = 'foo'; $builder = $this->DI->get('database')->setEntity('Test')->queryBuilder(); $this->assertEquals('foo', $builder->query); }
/** * Test getting the active modules * * @return void * @author Dan Cox */ public function test_getActive() { $this->config->shouldReceive('load'); $this->config->shouldReceive('params')->andReturn($this->config); $this->config->modules = []; $this->cache->shouldReceive('getCache')->andReturn(['mod' => []]); $library = new ModuleLibrary(); $active = $library->getActive(); $this->assertEquals(['mod'], $active); }
/** * Test the remove function * * @return void * @author Dan Cox */ public function test_remove() { $this->config->shouldReceive('load'); $this->config->shouldReceive('params')->andReturn($this->config); $this->config->mod = array('commands' => array(), 'entity' => array()); $this->config->shouldReceive('save'); $cache = new ModuleCache(); $cache->remove('mod'); $this->assertFalse(isset($this->config->mod)); }
/** * Get SQL from an update * * @return void * @author Dan Cox */ public function test_getSql() { $connection = $this->DI->get('connection'); $connection->shouldReceive('getSchemaTool')->once()->andReturn($this->schema); $connection->shouldReceive('connection')->once()->andReturn($connection); $connection->shouldReceive('getMetadataFactory')->once()->andReturn($this->metadataFactory); $this->metadataFactory->shouldReceive('getAllMetadata')->once()->andReturn(array()); $this->schema->shouldReceive('getUpdateSchemaSql')->once(); $this->DI->get('schema')->getSql(); }
/** * Test the whole process * * @return void * @author Dan Cox */ public function test_runThrough() { $sp = m::mock('skeletonprocess'); $collection = m::mock('collection'); $this->DI->addMock('skeletonprocess', $sp); $this->DI->addMock('collection', $collection); $this->DI->addMock('fs', $this->fs); $collection->shouldReceive('create')->andReturn($collection); $collection->deploy_script = array('mkdir [directory]', 'git clone [git]'); $this->fs->shouldReceive('exists')->andReturn(TRUE); $sp->shouldReceive('build')->with(['directory' => __DIR__, 'verbose' => false])->andReturn($sp); $sp->shouldReceive('getProcess')->andReturn($sp); $sp->shouldReceive('setArguments')->with(['mkdir', __DIR__])->andReturn($sp); $sp->shouldReceive('setArguments')->with(['git', 'clone', 'giturl'])->andReturn($sp); $sp->shouldReceive('setArguments')->with(['php', 'artisan', 'migrate'])->andReturn($sp); $sp->shouldReceive('mustRun'); $sp->shouldReceive('getCommandLine')->andReturn("'mkdir' '" . __DIR__ . "'"); $CT = new CommandTester($this->command); $CT->execute(['command' => $this->command->getName(), 'config' => 'test.yml', 'directory' => __DIR__, '--git' => 'giturl']); // Mkdir Passes... git fails $this->assertContains("Successfully ran command: 'mkdir'", $CT->getDisplay()); $this->assertContains("The command \"'git'", $CT->getDisplay()); }
/** * Test for when a command list is not valid * * @return void * @author Dan Cox */ public function test_commandListNotValid() { $this->setExpectedException('RuntimeException'); $this->database->shouldReceive('setModel')->with('Alice\\Entity\\Cron')->andReturn($this->database); $this->database->shouldReceive('count')->with(['id', '=', 1])->andReturn(1); $this->database->shouldReceive('find')->andReturn($this->database); $this->database->job = NULL; $this->database->name = 'test2'; $this->database->command = 'test'; $this->database->shouldReceive('setModel')->with('Alice\\Entity\\Command')->andReturn($this->database); $this->database->shouldReceive('count')->with(['name', '=', 'test'])->andReturn(0); $this->log->shouldReceive('write'); $CT = new CommandTester($this->command); $CT->execute(['command' => $this->command->getName(), 'cronid' => 1]); }
/** * Test with an invalid command list * * @return void * @author Dan Cox */ public function test_invalidCommandList() { $this->setExpectedException('RuntimeException'); // Cron $this->database->shouldReceive('setModel')->with('Alice\\Entity\\Cron')->andReturn($this->database); $this->database->shouldReceive('getEntity')->andReturn($this->database); $this->database->shouldReceive('count')->with(['name', '=', 'test'])->andReturn(1); $this->database->shouldReceive('first')->with(['name' => 'test'])->andReturn($this->database); $this->database->shouldReceive('save'); // Command List $this->database->shouldReceive('setModel')->with('Alice\\Entity\\Command')->andReturn($this->database); $this->database->shouldReceive('count')->with(['name', '=', 'test2'])->andReturn(0); $CT = new CommandTester($this->command); $CT->execute(['command' => $this->command->getName(), 'name' => 'test', '--commandlist' => 'test2']); }
/** * Fail, fail, fail * * @return void * @author Dan Cox */ public function test_activateWithFailedRequirements() { $this->setExpectedException('Alice\\Exceptions\\ModuleRequirementNotMetException'); $config = ['details' => ['name' => 'mod'], 'namespace' => '', 'extension' => 'module', 'requires' => ['mod2'], 'services' => []]; $this->config->shouldReceive('load')->andReturn($this->config); $this->config->shouldReceive('params')->andReturn($this->config); $this->config->shouldReceive('all')->andReturn($config); $this->probe->shouldReceive('load'); $this->probe->shouldReceive('class_exists')->andReturn(true); $this->probe->shouldReceive('reflection')->andReturn($this->reflection); $this->library->shouldReceive('getActive')->andReturn([]); $this->cache->shouldReceive('saveServices'); $this->cache->shouldReceive('readFrom'); $this->reflection->shouldReceive('getMethod')->andReturn($this->reflection); $this->reflection->shouldReceive('invokeArgs')->andReturn($this->reflection); $this->reflection->shouldReceive('newInstance'); $probe = new ModuleProbe(); $probe->load('test/'); $probe->activateModule(); }
/** * Test the disabled output switch * * @return void * @author Dan Cox */ public function test_disableOutput() { $this->builder->shouldReceive('disableOutput'); $this->process->disableOutput(); }