mirror of
https://gitee.com/hyperf/hyperf.git
synced 2024-12-05 21:28:15 +08:00
Fixed.
This commit is contained in:
parent
fce1695b91
commit
c3b3823967
@ -14,6 +14,7 @@ namespace HyperfTest\Database;
|
||||
|
||||
use Hyperf\Database\Migrations\MigrationCreator;
|
||||
use Hyperf\Utils\Filesystem\Filesystem;
|
||||
use HyperfTest\Database\Stubs\MigrationCreatorFakeMigration;
|
||||
use InvalidArgumentException;
|
||||
use Mockery;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
@ -86,18 +87,18 @@ class DatabaseMigrationCreatorTest extends TestCase
|
||||
public function testTableUpdateMigrationWontCreateDuplicateClass()
|
||||
{
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage('A MigrationCreatorFakeMigration class already exists.');
|
||||
$this->expectExceptionMessage('A HyperfTest\Database\Stubs\MigrationCreatorFakeMigration class already exists.');
|
||||
|
||||
$creator = $this->getCreator();
|
||||
$creator->getFilesystem()->shouldReceive('get');
|
||||
|
||||
$creator->create('migration_creator_fake_migration', 'foo');
|
||||
$creator->create(MigrationCreatorFakeMigration::class, 'foo');
|
||||
}
|
||||
|
||||
protected function getCreator()
|
||||
{
|
||||
$files = Mockery::mock(Filesystem::class);
|
||||
|
||||
$files->allows('put');
|
||||
return $this->getMockBuilder(MigrationCreator::class)->setMethods(['getDatePrefix'])->setConstructorArgs([$files])->getMock();
|
||||
}
|
||||
}
|
||||
|
@ -336,14 +336,18 @@ class ModelTest extends TestCase
|
||||
|
||||
public function testSaveIsCancelledIfSavingEventReturnsFalse()
|
||||
{
|
||||
Register::setEventDispatcher($events = Mockery::mock(Dispatcher::class));
|
||||
$events->shouldReceive('dispatch')->twice()->andReturn(null);
|
||||
|
||||
$model = $this->getMockBuilder(ModelStub::class)->setMethods(['newModelQuery'])->getMock();
|
||||
$query = Mockery::mock(Builder::class);
|
||||
$model->expects($this->once())->method('newModelQuery')->will($this->returnValue($query));
|
||||
|
||||
Register::setEventDispatcher($events = Mockery::mock(Dispatcher::class));
|
||||
$saving = new Events\Saving($model);
|
||||
$events->shouldReceive('dispatch')->once()->with($this->isInstanceOf(Events\Saving::class))->andReturn($saving);
|
||||
$model->exists = true;
|
||||
$events->shouldReceive('dispatch')->with($this->isInstanceOf(Saving::class))->andReturn($saving->setPropagation(true));
|
||||
|
||||
$model->exists = true;
|
||||
$this->assertFalse($model->save());
|
||||
}
|
||||
|
||||
@ -579,15 +583,15 @@ class ModelTest extends TestCase
|
||||
public function testInsertIsCancelledIfCreatingEventReturnsFalse()
|
||||
{
|
||||
Register::setEventDispatcher($events = Mockery::mock(Dispatcher::class));
|
||||
$events->shouldReceive('dispatch')->with($this->isInstanceOf(Events\Creating::class))->andReturn(false);
|
||||
$events->shouldReceive('dispatch')->once()->andReturn(null);
|
||||
$events->shouldReceive('dispatch')->twice()->andReturn(null);
|
||||
|
||||
$model = $this->getMockBuilder(ModelStub::class)->setMethods(['newModelQuery'])->getMock();
|
||||
$query = Mockery::mock(Builder::class);
|
||||
$query->shouldReceive('getConnection')->once();
|
||||
$query->shouldReceive('insertGetId')->once();
|
||||
$model->expects($this->once())->method('newModelQuery')->will($this->returnValue($query));
|
||||
|
||||
$event = new Events\Creating($model);
|
||||
$events->shouldReceive('dispatch')->once()->andReturn($event->setPropagation(true));
|
||||
|
||||
$this->assertFalse($model->save());
|
||||
$this->assertFalse($model->exists);
|
||||
}
|
||||
|
@ -1,6 +1,9 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace HyperfTest\Database\Stubs;
|
||||
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user