Skip to content

Commit

Permalink
Refactored test suite to use an in-memory database
Browse files Browse the repository at this point in the history
  • Loading branch information
giorgiosironi committed Jul 27, 2010
1 parent 0cd99e1 commit 14f2906
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 27 deletions.
6 changes: 4 additions & 2 deletions Scisr.php
Expand Up @@ -106,9 +106,11 @@ public function setOutput($output)
$this->_output = $output;
}

public static function createScisr($className = 'Scisr')
public static function createScisr($className = 'Scisr', $db = null)
{
$db = Scisr_Db::getDb();
if ($db === null) {
$db = Scisr_Db::getDb();
}
$dbFiles = new Scisr_Db_Files($db);
$dbFiles->init();
$dbFileIncludes = new Scisr_Db_FileIncludes($db);
Expand Down
2 changes: 1 addition & 1 deletion tests/FileCachingTest.php
Expand Up @@ -55,7 +55,7 @@ public function testDontUseIncompleteCacheResults() {
include "Foo.php"
EOL;
$this->populateFile($code);
$s = Scisr::createScisr();
$s = $this->getScisr();
$s->setRenameClassFile('Foo', 'Bar');
$s->addFile($this->test_file);
$s->run();
Expand Down
12 changes: 6 additions & 6 deletions tests/RenameClassFileSystemTest.php
Expand Up @@ -9,7 +9,7 @@ class RenameClassFileSystemTest extends Scisr_Tests_MultipleFileTestCase
public function testRenameClassFileAndCompareFile($oldName, $newName, $oldFile, $newFile) {
$this->populateDir(dirname(__FILE__) . '/_files/classFileFixture', $this->test_dir);

$s = Scisr::createScisr();
$s = $this->getScisr();
$s->setRenameClassFile($oldName, $newName);
$s->addFile($this->test_dir . '/' . $oldFile);
$s->run();
Expand All @@ -28,7 +28,7 @@ public function classFileProvider() {
public function testDontRenameClassFileWithoutAllowedExtension() {
$this->populateDir(dirname(__FILE__) . '/_files/classFileFixture', $this->test_dir);

$s = Scisr::createScisr();
$s = $this->getScisr();
$s->setRenameClassFile('MyOtherClass', 'NewClass');
$s->setAllowedFileExtensions(array('php'));
$s->addFile($this->test_dir);
Expand All @@ -41,7 +41,7 @@ public function testDontRenameClassFileWithoutAllowedExtension() {
public function testRenameClassFileWithFunnyExtension() {
$this->populateDir(dirname(__FILE__) . '/_files/classFileFixture', $this->test_dir);

$s = Scisr::createScisr();
$s = $this->getScisr();
$s->setRenameClassFile('StrangeClass', 'StrangeQuark');
$s->setAllowedFileExtensions(array('php', 'foo'));
$s->addFile($this->test_dir);
Expand All @@ -53,7 +53,7 @@ public function testRenameClassFileWithFunnyExtension() {
public function testRenameDirWithNamespacing() {
$this->populateDir(dirname(__FILE__) . '/_files/classFileNamespacedFixture', $this->test_dir);

$s = Scisr::createScisr();
$s = $this->getScisr();
$s->setRenameClassFile('Foo_Bar_Quark', 'Foo_Baz_Quack');
$s->addFile($this->test_dir);
$s->run();
Expand All @@ -64,7 +64,7 @@ public function testRenameDirWithNamespacing() {
public function testDontCreateDirNamespacingIfOriginalIsnt() {
$this->populateDir(dirname(__FILE__) . '/_files/classFileNamespacedFixture2', $this->test_dir);

$s = Scisr::createScisr();
$s = $this->getScisr();
$s->setRenameClassFile('Foo_Bar_Quark', 'Foo_Baz_Quack');
$s->addFile($this->test_dir);
$s->run();
Expand All @@ -75,7 +75,7 @@ public function testDontCreateDirNamespacingIfOriginalIsnt() {
public function testRenameClassFileAndCompareDir() {
$this->populateDir(dirname(__FILE__) . '/_files/classFileFixture-dir', $this->test_dir);

$s = Scisr::createScisr();
$s = $this->getScisr();
$s->setRenameClassFile('Foo', 'Baz');
$s->addFile($this->test_dir);
$s->run();
Expand Down
2 changes: 1 addition & 1 deletion tests/RenameClassFileTest.php
Expand Up @@ -7,7 +7,7 @@ class RenameClassFileTest extends Scisr_SingleFileTest
public function renameAndCompare($original, $expected, $oldname='Foo', $newname='Baz', $oldfile='Foo.php', $newfile='Baz.php', $aggressive=false) {
$this->populateFile($original);

$s = Scisr::createScisr();
$s = $this->getScisr();
if ($aggressive) {
$s->setEditMode(Scisr::MODE_AGGRESSIVE);
}
Expand Down
6 changes: 3 additions & 3 deletions tests/RenameClassSystemTest.php
Expand Up @@ -7,7 +7,7 @@ class RenameClassSystemTest extends Scisr_Tests_MultipleFileTestCase
public function testRenameClassAndCompareFile() {
$this->populateDir(dirname(__FILE__) . '/_files/cliFixture', $this->test_dir);

$s = Scisr::createScisr();
$s = $this->getScisr();
$s->setRenameClass('Foo', 'Baz');
$s->addFile($this->test_dir . '/test.php');
$s->run();
Expand All @@ -18,7 +18,7 @@ public function testRenameClassAndCompareFile() {
public function testRenameClassAndCompareFileWithRelativeDir() {
$this->populateDir(dirname(__FILE__) . '/_files/cliFixture', $this->test_dir);

$s = Scisr::createScisr();
$s = $this->getScisr();
$s->setRenameClass('Foo', 'Baz');
$s->addFile($this->rel_test_dir . '/test.php');
$s->run();
Expand All @@ -29,7 +29,7 @@ public function testRenameClassAndCompareFileWithRelativeDir() {
public function testRenameClassAndCompareDir() {
$this->populateDir(dirname(__FILE__) . '/_files/cliFixture', $this->test_dir);

$s = Scisr::createScisr();
$s = $this->getScisr();
$s->setRenameClass('Foo', 'Baz');
$s->addFile($this->test_dir);
$s->run();
Expand Down
2 changes: 1 addition & 1 deletion tests/RenameClassTest.php
Expand Up @@ -7,7 +7,7 @@ class RenameClassTest extends Scisr_SingleFileTest
public function renameAndCompare($original, $expected, $oldname='Foo', $newname='Baz', $aggressive=false) {
$this->populateFile($original);

$s = Scisr::createScisr();
$s = $this->getScisr();
if ($aggressive) {
$s->setEditMode(Scisr::MODE_AGGRESSIVE);
}
Expand Down
4 changes: 2 additions & 2 deletions tests/RenameFileSystemTest.php
Expand Up @@ -40,7 +40,7 @@ public function testRenameFileWithRelativePath() {
public function testDontMoveFileInTimidMode() {
$this->populateDir(dirname(__FILE__) . '/_files/renameFileFixture', $this->test_dir);

$s = Scisr::createScisr();
$s = $this->getScisr();
$s->setEditMode(Scisr::MODE_TIMID);
$s->setRenameFile($this->test_dir . '/test2.php', $this->test_dir . '/otherfolder/things.php');
$s->addFile($this->test_dir);
Expand Down Expand Up @@ -84,7 +84,7 @@ public function testRenameFileAltersIncludesSwitchPlaces() {
}

public function doRenameFile($old, $new) {
$s = Scisr::createScisr();
$s = $this->getScisr();
$s->setRenameFile($old, $new);
$s->addFile($this->test_dir);
$s->run();
Expand Down
2 changes: 1 addition & 1 deletion tests/RenameFileTest.php
Expand Up @@ -7,7 +7,7 @@ class RenameFileTest extends Scisr_SingleFileTest
public function renameAndCompare($original, $expected, $oldname='Foo.php', $newname='Baz.php', $aggressive=false) {
$this->populateFile($original);

$s = Scisr::createScisr();
$s = $this->getScisr();
if ($aggressive) {
$s->setEditMode(Scisr::MODE_AGGRESSIVE);
}
Expand Down
8 changes: 4 additions & 4 deletions tests/RenameMethodSystemTest.php
Expand Up @@ -7,7 +7,7 @@ class RenameMethodSystemTest extends Scisr_Tests_MultipleFileTestCase
public function testRenameMethodAndCompareFile() {
$this->populateDir(dirname(__FILE__) . '/_files/cliFixture', $this->test_dir);

$s = Scisr::createScisr();
$s = $this->getScisr();
$s->setRenameMethod('Foo', 'bar', 'quark', false);
$s->addFile($this->test_dir . '/test.php');
$s->run();
Expand All @@ -18,7 +18,7 @@ public function testRenameMethodAndCompareFile() {
public function testRenameMethodAndCompareDir() {
$this->populateDir(dirname(__FILE__) . '/_files/cliFixture', $this->test_dir);

$s = Scisr::createScisr();
$s = $this->getScisr();
$s->setRenameMethod('Foo', 'bar', 'quark', false);
$s->addFile($this->test_dir);
$s->run();
Expand All @@ -29,7 +29,7 @@ public function testRenameMethodAndCompareDir() {
public function testRenameMethodWithIncludedFile() {
$this->populateDir(dirname(__FILE__) . '/_files/renameMethodWithIncludesFixture', $this->test_dir);

$s = Scisr::createScisr();
$s = $this->getScisr();
$s->setRenameMethod('Foo', 'bar', 'baz', false);
$s->addFile($this->test_dir);
$s->run();
Expand All @@ -40,7 +40,7 @@ public function testRenameMethodWithIncludedFile() {
public function testClassInclusionOrder() {
$this->populateDir(dirname(__FILE__) . '/_files/renameMethodWithClassFixture', $this->test_dir);

$s = Scisr::createScisr();
$s = $this->getScisr();
$s->setRenameMethod('Foo', 'bar', 'baz', false);
// We want to force an ordering here
$s->addFile($this->test_dir . '/a.php');
Expand Down
4 changes: 2 additions & 2 deletions tests/RenameMethodTest.php
Expand Up @@ -7,7 +7,7 @@ class RenameMethodTest extends Scisr_SingleFileTest
public function renameAndCompare($original, $expected, $class='Foo', $oldmethod='bar', $newmethod='baz', $aggressive=false, $inheritance=false) {
$this->populateFile($original);

$s = Scisr::createScisr();
$s = $this->getScisr();
if ($aggressive) {
$s->setEditMode(Scisr::MODE_AGGRESSIVE);
}
Expand Down Expand Up @@ -1427,7 +1427,7 @@ public function testIncludeFileWhenClassUsedStatically() {
private function renameAndCompareWithIncludes($orig, $expected, $includedFile) {
$this->populateFile($orig);

$s = Scisr::createScisr();
$s = $this->getScisr();
$sniffer = new MockSniffer($s->getFactory()->getCollaborator('Scisr_Db_Classes'), $s->getFactory()->getCollaborator('Scisr_Db_VariableTypes'));
$sniffer->incFile = $includedFile;
$sniffer->test_file = $this->test_file;
Expand Down
4 changes: 2 additions & 2 deletions tests/ScisrSingleFileTest.php
Expand Up @@ -7,12 +7,12 @@ class ScisrTest extends Scisr_SingleFileTest
public function parseCode($code) {
$this->populateFile($code);

$s = Scisr::createScisr();
$s = $this->getScisr();
$s->setRenameClass('dummy', 'dummy2');
$s->addFile($this->test_file);
$s->run();

$s = Scisr::createScisr();
$s = $this->getScisr();
$s->setRenameMethod('DummyClass', 'dummy', 'dummy2', false);
$s->addFile($this->test_file);
$s->run();
Expand Down
12 changes: 10 additions & 2 deletions tests/Scisr_TestCase.php
Expand Up @@ -6,14 +6,22 @@ class Scisr_TestCase extends PHPUnit_Framework_TestCase
{

public function setUp() {
Scisr_Db::clearDb();
chdir(dirname(__FILE__));
}

public function tearDown() {
Scisr_Db::clearDb();
Scisr_ChangeRegistry::clearAll();
chdir(dirname(__FILE__));
}

public function getDb()
{
return new PDO('sqlite::memory:');
}

public function getScisr($className = 'Scisr')
{
return Scisr::createScisr($className, $this->getDb());
}

}

0 comments on commit 14f2906

Please sign in to comment.