forked from FriendsOfCake/fixturize
-
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
0 parents
commit 159a3ba
Showing
6 changed files
with
231 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
; This file is for unifying the coding style for different editors and IDEs. | ||
; More information at http://editorconfig.org | ||
|
||
root = false | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 4 | ||
charset = "utf-8" | ||
end_of_line = lf | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
|
||
[*.yml] | ||
indent_style = space | ||
indent_size = 2 |
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,6 @@ | ||
*.pyc | ||
docs/_build | ||
phpunit.xml | ||
vendor/ | ||
composer.lock | ||
tmp |
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,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2013 Christian "Jippi" Winther | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
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,37 @@ | ||
[](https://packagist.org/packages/FriendsOfCake/fixturize) | ||
|
||
# Installation | ||
|
||
For CakePHP 3.x compatible version: | ||
|
||
``` | ||
composer require friendsofcake/fixturize | ||
``` | ||
|
||
# Introduction | ||
|
||
The fixturize plugin will help improve performance of your fixture based tests. | ||
|
||
This plugin currently only work with MySQL databases. | ||
|
||
# Usage | ||
|
||
Instead of ``use Cake\TestSuite\Fixture\TestFixture;`` simply use ``use FriendsOfCake\Fixturize\TestSuite\Fixture\ChecksumTestFixture as TestFixture;``. | ||
|
||
Re-run your tests and enjoy the speed! | ||
|
||
# Bugs | ||
|
||
If you happen to stumble upon a bug, please feel free to create a pull request with a fix | ||
(optionally with a test), and a description of the bug and how it was resolved. | ||
|
||
You can also create an issue with a description to raise awareness of the bug. | ||
|
||
# Features | ||
|
||
If you have a good idea for a Crud feature, please join us on IRC and let's discuss it. Pull | ||
requests are always more than welcome. | ||
|
||
# Support / Questions | ||
|
||
You can join us on IRC in the #FriendsOfCake channel for any support or questions. |
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,40 @@ | ||
{ | ||
"name": "friendsofcake/fixturize", | ||
"description": "CakePHP Fixture classes to help increase productivity or performance", | ||
"type": "cakephp-plugin", | ||
"keywords": [ | ||
"cakephp", | ||
"fixture", | ||
"fixtures", | ||
"unittest", | ||
"phpunit", | ||
"performance" | ||
], | ||
"homepage": "https://github.com/FriendsOfCake/fixturize", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Christian Winther", | ||
"role": "Author", | ||
"homepage": "http://cakephp.nu/" | ||
}, | ||
{ | ||
"name": "José Lorenzo Rodríguez", | ||
"role": "Contributor", | ||
"homepage": "https://github.com/lorenzo" | ||
} | ||
], | ||
"autoload": { | ||
"psr-4": { | ||
"FriendsOfCake\\Fixture\\": "src" | ||
} | ||
}, | ||
"require": { | ||
"cakephp/cakephp": "^3.2" | ||
}, | ||
"support": { | ||
"source": "https://github.com/FriendsOfCake/fixturize", | ||
"issues": "https://github.com/FriendsOfCake/fixturize/issues", | ||
"irc": "irc://irc.freenode.org/cakephp" | ||
} | ||
} |
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,111 @@ | ||
<?php | ||
namespace FriendsOfCake\Fixturize\TestSuite\Fixture; | ||
|
||
use Cake\TestSuite\Fixture\TestFixture; | ||
use Cake\Datasource\ConnectionInterface; | ||
|
||
/** | ||
* This class will inspect the database table hash and detect any change to the underlying | ||
* data set and automatically re-create the table and data | ||
* | ||
* If no data has changed, the usual truncate/insert flow is bypassed, increasing the speed | ||
* of the test suite with heavy fixture usage up significantly. | ||
* | ||
*/ | ||
class ChecksumTestFixture extends TestFixture | ||
{ | ||
|
||
/** | ||
* List of table hashes | ||
* | ||
* @var array | ||
*/ | ||
public static $_tableHashes = []; | ||
|
||
/** | ||
* Inserts records in the database | ||
* | ||
* This will only happen if the underlying table is modified in any way or | ||
* does not exist with a hash yet. | ||
* | ||
* @param ConnectionInterface $db | ||
* @return boolean | ||
*/ | ||
public function insert(ConnectionInterface $db) | ||
{ | ||
if ($this->_tableUnmodified($db)) { | ||
return true; | ||
} | ||
|
||
$result = parent::insert($db); | ||
static::$_tableHashes[$this->table] = $this->_hash($db); | ||
return $result; | ||
} | ||
|
||
/** | ||
* Deletes all table information. | ||
* | ||
* This will only happen if the underlying table is modified in any way | ||
* | ||
* @param ConnectionInterface $db | ||
* @return void | ||
*/ | ||
public function truncate(ConnectionInterface $db) | ||
{ | ||
if ($this->_tableUnmodified($db)) { | ||
return true; | ||
} | ||
|
||
return parent::truncate($db); | ||
} | ||
|
||
/** | ||
* Drops the table from the test datasource | ||
* | ||
* @param ConnectionInterface $db | ||
* @return void | ||
*/ | ||
public function drop(ConnectionInterface $db) | ||
{ | ||
unset(static::$_tableHashes[$this->table]); | ||
return parent::drop($db); | ||
} | ||
|
||
/** | ||
* Test if a table is modified or not | ||
* | ||
* If there is no known hash, treat it as being modified | ||
* | ||
* In all other cases where the initial and current hash differs, assume | ||
* the table has changed | ||
* | ||
* @param DboSource $db | ||
* @return boolean | ||
*/ | ||
protected function _tableUnmodified($db) | ||
{ | ||
if (empty(static::$_tableHashes[$this->table])) { | ||
return false; | ||
} | ||
|
||
if (static::$_tableHashes[$this->table] === $this->_hash($db)) { | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
/** | ||
* Get the table hash from MySQL for a specific table | ||
* | ||
* @param ConnectionInterface $db | ||
* @return string | ||
*/ | ||
protected function _hash(ConnectionInterface $db) | ||
{ | ||
$sth = $db->execute("CHECKSUM TABLE " . $this->table); | ||
$result = $sth->fetch('assoc'); | ||
$checksum = $result['Checksum']; | ||
return $checksum; | ||
} | ||
} |