예제 #1
0
 /**
  * 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());
 }
예제 #2
0
 /**
  * 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());
 }
예제 #3
0
 /**
  * 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);
 }
예제 #5
0
 /**
  * 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']);
 }
예제 #6
0
 /**
  * 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());
 }
예제 #7
0
파일: LogTest.php 프로젝트: danzabar/alice
 /**
  * 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()));
 }
예제 #8
0
 /**
  * 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);
 }
예제 #9
0
 /**
  * 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());
 }
예제 #10
0
 /**
  * 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());
 }
예제 #11
0
 /**
  * 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());
 }
예제 #12
0
 /**
  * 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());
 }
예제 #13
0
 /**
  * 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');
 }
예제 #14
0
파일: CronTest.php 프로젝트: danzabar/alice
 /**
  * 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();
 }
예제 #15
0
 /**
  * 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']);
 }
예제 #16
0
 /**
  * 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());
 }
예제 #17
0
 /**
  * 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();
 }
예제 #18
0
 /**
  * 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']);
 }
예제 #19
0
 /**
  * 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__]);
 }
예제 #20
0
 /**
  * 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);
 }
예제 #21
0
 /**
  * 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);
 }
예제 #22
0
 /**
  * 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));
 }
예제 #23
0
 /**
  * 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();
 }
예제 #24
0
 /**
  * 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());
 }
예제 #25
0
 /**
  * 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]);
 }
예제 #26
0
 /**
  * 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']);
 }
예제 #27
0
 /**
  * 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();
 }
예제 #28
0
 /**
  * Test the disabled output switch
  *
  * @return void
  * @author Dan Cox
  */
 public function test_disableOutput()
 {
     $this->builder->shouldReceive('disableOutput');
     $this->process->disableOutput();
 }