-
Notifications
You must be signed in to change notification settings - Fork 893
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow a way to insert demo data only for empty table.
- Loading branch information
1 parent
da812b9
commit 5d7556a
Showing
3 changed files
with
90 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
namespace Test\Phinx\Seed; | ||
|
||
use PDOStatement; | ||
use Phinx\Db\Adapter\PdoAdapter; | ||
use Phinx\Seed\AbstractSeed; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class SeedTest extends TestCase | ||
{ | ||
/** | ||
* @return void | ||
*/ | ||
public function testHasData(): void | ||
{ | ||
$queryStub = $this->getMockBuilder(PDOStatement::class)->disableOriginalConstructor()->getMock(); | ||
$queryStub->expects($this->once()) | ||
->method('fetchAll') | ||
->will($this->returnValue([0 => ['count' => 0]])); | ||
|
||
$adapterStub = $this->getMockBuilder(PdoAdapter::class) | ||
->setConstructorArgs([[]]) | ||
->getMock(); | ||
$adapterStub->expects($this->once()) | ||
->method('query') | ||
->will($this->returnValue($queryStub)); | ||
|
||
$stub = $this->getMockForAbstractClass(AbstractSeed::class); | ||
$stub->setAdapter($adapterStub); | ||
$result = $stub->hasData('foo'); | ||
|
||
$this->assertFalse($result); | ||
} | ||
|
||
/** | ||
* @return void | ||
*/ | ||
public function testHasDataTrue(): void | ||
{ | ||
$queryStub = $this->getMockBuilder(PDOStatement::class)->disableOriginalConstructor()->getMock(); | ||
$queryStub->expects($this->once()) | ||
->method('fetchAll') | ||
->will($this->returnValue([0 => ['count' => 1]])); | ||
|
||
$adapterStub = $this->getMockBuilder(PdoAdapter::class) | ||
->setConstructorArgs([[]]) | ||
->getMock(); | ||
$adapterStub->expects($this->once()) | ||
->method('query') | ||
->will($this->returnValue($queryStub)); | ||
|
||
$stub = $this->getMockForAbstractClass(AbstractSeed::class); | ||
$stub->setAdapter($adapterStub); | ||
$result = $stub->hasData('foo'); | ||
|
||
$this->assertTrue($result); | ||
} | ||
} |