本文整理汇总了PHP中Cake\ORM\TableRegistry::set方法的典型用法代码示例。如果您正苦于以下问题:PHP TableRegistry::set方法的具体用法?PHP TableRegistry::set怎么用?PHP TableRegistry::set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cake\ORM\TableRegistry
的用法示例。
在下文中一共展示了TableRegistry::set方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
/**
* Set up
*
* @return void
*/
public function setUp()
{
parent::setUp();
$this->tag = $this->getMock('Cake\\ORM\\Table', ['find', 'delete'], [['alias' => 'Tags', 'table' => 'tags']]);
$this->tag->schema(['id' => ['type' => 'integer'], 'name' => ['type' => 'string'], '_constraints' => ['primary' => ['type' => 'primary', 'columns' => ['id']]]]);
$this->article = $this->getMock('Cake\\ORM\\Table', ['find', 'delete'], [['alias' => 'Articles', 'table' => 'articles']]);
$this->article->schema(['id' => ['type' => 'integer'], 'name' => ['type' => 'string'], '_constraints' => ['primary' => ['type' => 'primary', 'columns' => ['id']]]]);
TableRegistry::set('Articles', $this->article);
TableRegistry::get('ArticlesTags', ['table' => 'articles_tags', 'schema' => ['article_id' => ['type' => 'integer'], 'tag_id' => ['type' => 'integer'], '_constraints' => ['primary' => ['type' => 'primary', 'columns' => ['article_id', 'tag_id']]]]]);
$this->tagsTypeMap = new TypeMap(['Tags.id' => 'integer', 'id' => 'integer', 'Tags.name' => 'string', 'name' => 'string']);
$this->articlesTagsTypeMap = new TypeMap(['ArticlesTags.article_id' => 'integer', 'article_id' => 'integer', 'ArticlesTags.tag_id' => 'integer', 'tag_id' => 'integer']);
}
示例2: testRunExecuteJob
/**
* @return void
* @covers ::run
*/
public function testRunExecuteJob()
{
$table = $this->getModel('\\DelayedJobs\\Model\\Table\\DelayedJobsTable', ['get'], 'DelayedJobs', 'delayed_jobs');
TableRegistry::set('DelayedJobs.DelayedJobs', $table);
$job_data = Fabricate::attributes_for('DelayedJobs.DelayedJobs')[0];
$job = $this->getMock('\\DelayedJobs\\Model\\Entity\\DelayedJob', ['execute'], [$job_data]);
$job_output = 'Test completed';
$table->expects($this->once())->method('get')->willReturn($job);
$job->expects($this->once())->method('execute')->willReturn($job_output);
$this->get('/delayed_jobs/run/' . $job->id);
$this->assertSession('Job Completed: ' . $job_output, 'Flash.flash.message');
$this->assertResponseSuccess();
$this->assertRedirect(['action' => 'index']);
}
示例3: testUrl
/**
* Test initial setup
*
* @return void
*/
public function testUrl()
{
// mock of entity
$filename = 'test.jpg';
$entity = $this->getMock('Cake\\ORM\\Entity', ['source', 'get']);
$entity->expects($this->once())->method('source')->will($this->returnValue('TestTables'));
$entity->expects($this->once())->method('get')->will($this->returnValue($filename));
// mock of table
$table = $this->getMock('Cake\\ORM\\Table', ['getUploadFolder']);
$table->expects($this->once())->method('getUploadFolder')->will($this->returnValue('/path/to/folder/'));
TableRegistry::set('TestTables', $table);
// test
$url = $this->Upload->url($entity, 'test_field');
$this->assertContains($filename, $url);
}
示例4: testInjectSearch
/**
* Test inject search
*
* @return void
*/
public function testInjectSearch()
{
\Cake\Core\Plugin::load('Search', ['path' => ROOT . DS]);
$params = ['search' => ['name' => '1st post']];
$request = new \Cake\Network\Request();
$response = new \Cake\Network\Response();
$eventManager = new \Cake\Event\EventManager();
$controller = new \Cake\Controller\Controller($request, $response, 'Search', $eventManager);
$tableMock = $this->getMockBuilder('\\Cake\\ORM\\Table')->setMockClassName('SearchTables')->setMethods(['filterParams'])->getMock();
$tableMock->expects($this->once())->method('filterParams')->will($this->returnCallback(function () use($params) {
return $params;
}));
\Cake\ORM\TableRegistry::set('Search', $tableMock);
$queryMock = $this->getMockBuilder('\\Cake\\ORM\\Query')->disableOriginalConstructor()->getMock();
$queryMock->expects($this->once())->method('find')->with('search', $params)->will($this->returnValue($queryMock));
$subject = new \Crud\Event\Subject();
$subject->query = $queryMock;
$event = new \Cake\Event\Event('Crud.beforeLookup', $subject);
$listener = new \Crud\Listener\SearchListener($controller, ['enabled' => ['Crud.beforeLookup']]);
$listener->injectSearch($event);
}
示例5: getMockForModel
/**
* Mock a model, maintain fixtures and table association
*
* @param string $alias
* @param array $methods
* @param array $options
* @throws \Cake\ORM\Error\MissingTableClassException
* @return Model
*/
public function getMockForModel($alias, array $methods = array(), array $options = array())
{
if (empty($options['className'])) {
$class = Inflector::camelize($alias);
$className = App::classname($class, 'Model/Table', 'Table');
if (!$className) {
throw new \Cake\ORM\Error\MissingTableClassException(array($alias));
}
$options['className'] = $className;
}
list($plugin, $baseClass) = pluginSplit($alias);
$options += ['alias' => $baseClass] + TableRegistry::config($alias);
$mock = $this->getMock($options['className'], $methods, array($options));
TableRegistry::set($alias, $mock);
return $mock;
}
示例6: getMockForModel
/**
* Mock a model, maintain fixtures and table association
*
* @param string $alias The model to get a mock for.
* @param mixed $methods The list of methods to mock
* @param array $options The config data for the mock's constructor.
* @throws \Cake\ORM\Exception\MissingTableClassException
* @return \Cake\ORM\Table|\PHPUnit_Framework_MockObject_MockObject
*/
public function getMockForModel($alias, array $methods = [], array $options = [])
{
if (empty($options['className'])) {
$class = Inflector::camelize($alias);
$className = App::className($class, 'Model/Table', 'Table');
if (!$className) {
throw new MissingTableClassException([$alias]);
}
$options['className'] = $className;
}
$connectionName = $options['className']::defaultConnectionName();
$connection = ConnectionManager::get($connectionName);
list(, $baseClass) = pluginSplit($alias);
$options += ['alias' => $baseClass, 'connection' => $connection];
$options += TableRegistry::config($alias);
$mock = $this->getMock($options['className'], $methods, [$options]);
if (empty($options['entityClass']) && $mock->entityClass() === '\\Cake\\ORM\\Entity') {
$parts = explode('\\', $options['className']);
$entityAlias = Inflector::singularize(substr(array_pop($parts), 0, -5));
$entityClass = implode('\\', array_slice($parts, 0, -1)) . '\\Entity\\' . $entityAlias;
if (class_exists($entityClass)) {
$mock->entityClass($entityClass);
}
}
TableRegistry::set($baseClass, $mock);
return $mock;
}
示例7: testSetPlugin
/**
* Test setting an instance with plugin syntax aliases
*
* @return void
*/
public function testSetPlugin()
{
Plugin::load('TestPlugin');
$mock = $this->getMock('TestPlugin\\Model\\Table\\CommentsTable');
$this->assertSame($mock, TableRegistry::set('TestPlugin.Comments', $mock));
$this->assertSame($mock, TableRegistry::get('TestPlugin.Comments'));
$this->assertSame($mock, TableRegistry::get('Comments'));
}
示例8: getMockForModel
/**
* Mock a model, maintain fixtures and table association
*
* @param string $alias The model to get a mock for.
* @param mixed $methods The list of methods to mock
* @param array $options The config data for the mock's constructor.
* @throws \Cake\ORM\Exception\MissingTableClassException
* @return Model
*/
public function getMockForModel($alias, array $methods = array(), array $options = array())
{
if (empty($options['className'])) {
$class = Inflector::camelize($alias);
$className = App::className($class, 'Model/Table', 'Table');
if (!$className) {
throw new \Cake\ORM\Exception\MissingTableClassException(array($alias));
}
$options['className'] = $className;
}
$connectionName = $options['className']::defaultConnectionName();
$connection = ConnectionManager::get($connectionName);
list($plugin, $baseClass) = pluginSplit($alias);
$options += ['alias' => $baseClass, 'connection' => $connection];
$options += TableRegistry::config($alias);
$mock = $this->getMock($options['className'], $methods, [$options]);
TableRegistry::set($alias, $mock);
return $mock;
}
示例9: testSet
/**
* Test setting an instance.
*
* @return void
*/
public function testSet()
{
$mock = $this->getMock('Cake\\ORM\\Table');
$this->assertSame($mock, TableRegistry::set('Articles', $mock));
$this->assertSame($mock, TableRegistry::get('Articles'));
}
示例10: testSet
/**
* Test the get() method.
*
* @return void
*/
public function testSet()
{
$table = $this->getMock('Cake\\ORM\\Table');
$locator = $this->_setMockLocator();
$locator->expects($this->once())->method('set')->with('Test', $table);
TableRegistry::set('Test', $table);
}