forked from mavinoo/laravelBatch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Zacchaeus Bolaji
committed
Nov 4, 2019
1 parent
20328c1
commit 7ecc59c
Showing
6 changed files
with
267 additions
and
159 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
<?php | ||
require_once ('BootstrapDatabase.php'); | ||
|
||
class BatchInsertTest extends BootstrapDatabase | ||
{ | ||
public $columns = [ | ||
'email', | ||
'password', | ||
'name', | ||
'status', | ||
]; | ||
|
||
public function testBatchInsertWithFacade() | ||
{ | ||
$values = [ | ||
[ | ||
'[email protected]', | ||
bcrypt('djunehor'), | ||
'djunehor', | ||
'active' | ||
], | ||
[ | ||
'[email protected]', | ||
bcrypt('samuel'), | ||
'samuel', | ||
'whodey' | ||
], | ||
[ | ||
'[email protected]', | ||
bcrypt('general'), | ||
'general', | ||
'inactive', | ||
] | ||
]; | ||
$batchSize = 500; // insert 500 (default), 100 minimum rows in one query | ||
|
||
$result = Batch::insert($this->model, $this->columns, $values, $batchSize); | ||
|
||
$this->assertIsArray($result); | ||
$this->assertTrue($result['totalRows'] == 3); | ||
$this->assertTrue($result['totalBatch'] == 500); | ||
$this->model->truncate(); | ||
} | ||
|
||
public function testBatchInsertIncorrectColumnCount() | ||
{ | ||
|
||
$columns = [ | ||
'email', | ||
'password', | ||
'name', | ||
'status', | ||
]; | ||
|
||
$values = [ | ||
[ | ||
'[email protected]', | ||
bcrypt('djunehor'), | ||
'djunehor', | ||
], | ||
[ | ||
'[email protected]', | ||
bcrypt('samuel'), | ||
'samuel', | ||
'whodey' | ||
], | ||
[ | ||
'[email protected]', | ||
bcrypt('general'), | ||
'general', | ||
'inactive', | ||
] | ||
]; | ||
$batchSize = 500; // insert 500 (default), 100 minimum rows in one query | ||
|
||
$result = Batch::insert($this->model, $this->columns, $values, $batchSize); | ||
$this->assertFalse($result); | ||
} | ||
|
||
|
||
public function testBatchInsertWithHelper() | ||
{ | ||
$values = [ | ||
[ | ||
'[email protected]', | ||
bcrypt('djunehor'), | ||
'djunehor', | ||
'active' | ||
], | ||
[ | ||
'[email protected]', | ||
bcrypt('samuel'), | ||
'samuel', | ||
'whodey' | ||
], | ||
[ | ||
'[email protected]', | ||
bcrypt('general'), | ||
'general', | ||
'inactive', | ||
] | ||
]; | ||
$batchSize = 500; // insert 500 (default), 100 minimum rows in one query | ||
|
||
$result = batch()->insert($this->model, $this->columns, $values, $batchSize); | ||
|
||
$this->assertIsArray($result); | ||
$this->assertTrue($result['totalRows'] == 3); | ||
$this->assertTrue($result['totalBatch'] == 500); | ||
$this->model->truncate(); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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,98 @@ | ||
<?php | ||
require_once ('BootstrapDatabase.php'); | ||
use Carbon\Carbon; | ||
|
||
class BatchUpdateTest extends BootstrapDatabase | ||
{ | ||
public $columns = [ | ||
'email', | ||
'password', | ||
'name', | ||
'status', | ||
]; | ||
|
||
private function insert() | ||
{ | ||
$values = [ | ||
[ | ||
'[email protected]', | ||
bcrypt('djunehor'), | ||
'djunehor', | ||
'active' | ||
], | ||
[ | ||
'[email protected]', | ||
bcrypt('samuel'), | ||
'samuel', | ||
'whodey' | ||
], | ||
[ | ||
'[email protected]', | ||
bcrypt('general'), | ||
'general', | ||
'inactive', | ||
] | ||
]; | ||
$batchSize = 500; // insert 500 (default), 100 minimum rows in one query | ||
|
||
$result = Batch::insert($this->model, $this->columns, $values, $batchSize); | ||
|
||
$this->assertIsArray($result); | ||
$this->assertTrue($result['totalRows'] == 3); | ||
$this->assertTrue($result['totalBatch'] == 500); | ||
} | ||
|
||
public function testBatchUpdateWithFacade() | ||
{ | ||
$this->insert(); | ||
$columnValues = [ | ||
[ | ||
'id' => 1, | ||
'status' => 'amala' | ||
], | ||
[ | ||
'id' => 2, | ||
'status' => 'deactive', | ||
'name' => 'Ghanbari' | ||
], | ||
[ | ||
'id' => 3, | ||
'status' => 'active', | ||
'created_at' => Carbon::now() | ||
] | ||
]; | ||
$index = 'id'; | ||
|
||
$result = Batch::update($this->model, $columnValues, $index); | ||
|
||
$this->assertTrue($result == 3); | ||
$this->model->truncate(); | ||
} | ||
|
||
public function testBatchUpdateWithHelper() | ||
{ | ||
$this->insert(); | ||
$columnValues = [ | ||
[ | ||
'id' => 1, | ||
'status' => 'amala' | ||
], | ||
[ | ||
'id' => 2, | ||
'status' => 'deactive', | ||
'name' => 'Ghanbari' | ||
], | ||
[ | ||
'id' => 3, | ||
'status' => 'active', | ||
'created_at' => Carbon::now() | ||
] | ||
]; | ||
$index = 'id'; | ||
|
||
$result = batch()->update($this->model, $columnValues, $index); | ||
|
||
$this->assertTrue($result == 3); | ||
$this->model->truncate(); | ||
} | ||
} |
Oops, something went wrong.