Skip to content

Commit

Permalink
Upgrading the SimpleTest library. Adding a mock object and new
Browse files Browse the repository at this point in the history
tests. Precursor to actual database tests.

.
  • Loading branch information
brandonsavage committed Jan 8, 2013
1 parent cc67ba3 commit 03f65fb
Show file tree
Hide file tree
Showing 138 changed files with 24,868 additions and 21,157 deletions.
3 changes: 2 additions & 1 deletion bouncer/php/lib/sdo.php
Expand Up @@ -198,7 +198,8 @@ function build_query($base, $args=null) {

array_walk($args, array($this, 'escape_string'));
// array_merge now requires a type-cast to handle strings (changed in PHP5)
return call_user_func_array('sprintf', array_merge((array)$base, $args));
$query = call_user_func_array('sprintf', array_merge((array)$base, $args));
return $query;
}

/**
Expand Down
44 changes: 44 additions & 0 deletions bouncer/tests/functions.php
@@ -0,0 +1,44 @@
<?php
/**
* To run this test from this directory:
* $ php -q functions.php
* sdotest
* OK
* Test cases run: 1/1, Passes: 4, Failures: 0, Exceptions: 0
*/

if (! defined('SIMPLE_TEST')) {
define('SIMPLE_TEST', 'simpletest/');
}
require_once(SIMPLE_TEST . 'unit_tester.php');
require_once(SIMPLE_TEST . 'reporter.php');
require_once('../php/cfg/config.php');
require_once('../php/lib/memcaching.php');
require_once('../php/lib/sdo.php');
require_once('../php/functions.php');

# Include the mocks
require_once('./mocks/sdo.php');

class FunctionsTest extends UnitTestCase {


function testQueryForMirrorsStandalone() {
$sdo_mock = new SDO_Mock();
$mirrors = queryForMirrors($sdo_mock, 'http', 1, 1);


$this->assertTrue(empty($mirrors), 'Mirrors not empty.');
$this->assertEqual($sdo_mock->requestCount, 2, 'Incorrect number of requests made to database');

$sdo_mock->resetCount();
$sdo_mock->returnJunk = true;
$mirrors = queryForMirrors($sdo_mock, 'http', 1, 1);

$this->assertFalse(empty($mirrors), 'Mirrors are empty');
$this->assertEqual($sdo_mock->requestCount, 1, 'Incorrect number of requests made to database');
}
}

$test = new FunctionsTest();
$test->run(new TextReporter());
21 changes: 21 additions & 0 deletions bouncer/tests/mocks/sdo.php
@@ -0,0 +1,21 @@
<?php

class SDO_Mock
{
public $requestCount = 0;
public $returnJunk = false;

public function get($query,$args,$type=MYSQL_BOTH,$col_id=null) {
$this->requestCount += 1;

if($this->returnJunk) {
return array(true);
} else {
return array();
}
}

public function resetCount() {
$this->requestCount = 0;
}
}
2 changes: 1 addition & 1 deletion bouncer/tests/sdo.php
Expand Up @@ -120,6 +120,6 @@ function testCacheEntries() {
}
}

$test = &new SDOTest();
$test = new SDOTest();
$test->run(new TextReporter());
?>
55 changes: 53 additions & 2 deletions bouncer/tests/simpletest/HELP_MY_TESTS_DONT_WORK_ANYMORE 100644 → 100755
Expand Up @@ -5,13 +5,64 @@ written with earlier versions will fail with the newest ones. The most
dramatic changes are in the alpha releases. Here is a list of possible
problems and their fixes...

assertText() no longer finds a string inside a <script> tag
-----------------------------------------------------------
The assertText() method is intended to match only visible,
human-readable text on the web page. Therefore, the contents of script
tags should not be matched by this assertion. However there was a bug
in the text normalisation code of simpletest which meant that <script>
tags spanning multiple lines would not have their content stripped
out. If you want to check the content of a <script> tag, use
assertPattern(), or write a custom expectation.

Overloaded method not working
-----------------------------
All protected and private methods had underscores
removed. This means that any private/protected methods that
you overloaded with those names need to be updated.

Fatal error: Call to undefined method Classname::classname()
------------------------------------------------------------
SimpleTest renamed all of its constructors from
Classname to __construct; derived classes invoking
their parent constructors should replace parent::Classname()
with parent::__construct().

Custom CSS in HtmlReporter not being applied
--------------------------------------------
Batch rename of protected and private methods
means that _getCss() was renamed to getCss().
Please rename your method and it should work again.

setReturnReference() throws errors in E_STRICT
----------------------------------------------
Happens when an object is passed by reference.
This also happens with setReturnReferenceAt().
If you want to return objects then replace these
with calls to returns() and returnsAt() with the
same arguments. This change was forced in the 1.1
version for E_STRICT compatibility.

assertReference() throws errors in E_STRICT
-------------------------------------------
Due to language restrictions you cannot compare
both variables and objects in E_STRICT mode. Use
assertSame() in this mode with objects. This change
was forced the 1.1 version.

Cannot create GroupTest
-----------------------
The GroupTest has been renamed TestSuite (see below).
It was removed completely in 1.1 in favour of this
name.

No method getRelativeUrls() or getAbsoluteUrls()
------------------------------------------------
These methods were always a bit weird anyway, and
the new parsing of the base tag makes them more so.
They have been replaced with getUrls() instead. If
you want the old functionality then simply chop
off the current domain from getUrl().
off the current domain from getUrls().

Method setWildcard() removed in mocks
-------------------------------------
Expand Down Expand Up @@ -48,7 +99,7 @@ getTransferError() call on the web tester to see if
there was a socket level error in a fetch. This check
is now always carried out by the WebTestCase unless
the fetch is prefaced with WebTestCase::ignoreErrors().
The ignore directive only lasts for test case fetching
The ignore directive only lasts for the next fetching
action such as get() and click().

No method SimpleTestOptions::ignore()
Expand Down
Empty file modified bouncer/tests/simpletest/LICENSE 100644 → 100755
Empty file.
90 changes: 42 additions & 48 deletions bouncer/tests/simpletest/README 100644 → 100755
@@ -1,16 +1,18 @@
SimpleTest
==========
You probably got this package from...
http://simpletest.sourceforge.net/projects/simpletest/

You probably got this package from:

http://simpletest.org/en/download.html

If there is no licence agreement with this package please download
a version from the location above. You must read and accept that
licence to use this software. The file is titled simply LICENSE.

What is it? It's a framework for unit testing, web site testing and
mock objects for PHP 4.2.0+.
mock objects for PHP 5.0.5+.

If you have used JUnit you will find this PHP unit testing version very
If you have used JUnit, you will find this PHP unit testing version very
similar. Also included is a mock objects and server stubs generator.
The stubs can have return values set for different arguments, can have
sequences set also by arguments and can return items by reference.
Expand All @@ -21,88 +23,80 @@ A web tester similar in concept to JWebUnit is also included. There is no
JavaScript or tables support, but forms, authentication, cookies and
frames are handled.

You can see a release schedule at http://www.lastcraft.com/overview.php
You can see a release schedule at http://simpletest.org/en/overview.html
which is also copied to the documentation folder with this release.
A full PHPDocumenter API documentation exists at
http://simpletest.sourceforge.net/.
http://simpletest.org/api/.

The user interface is minimal
in the extreme, but a lot of information flows from the test suite.
After version 1.0 we will release a better web UI, but we are leaving XUL
and GTk versions to volunteers as everybody has their own opinion
on a good GUI, and we don't want to discourage development by shipping
one with the toolkit.
The user interface is minimal in the extreme, but a lot of information
flows from the test suite. After version 1.0 we will release a better
web UI, but we are leaving XUL and GTK versions to volunteers as
everybody has their own opinion on a good GUI, and we don't want to
discourage development by shipping one with the toolkit. You can
download an Eclipse plug-in separately.

You are looking at a first full release. The unit tests for SimpleTest
itself can be run here...
The unit tests for SimpleTest itself can be run here:

simpletest/test/unit_tests.php
test/unit_tests.php

And tests involving live network connections as well are here...
And tests involving live network connections as well are here:

simpletest/test/all_tests.php
test/all_tests.php

The full tests will typically overrun the 8Mb limit usually allowed
The full tests will typically overrun the 8Mb limit often allowed
to a PHP process. A workaround is to run the tests on the command
with a custom php.ini file if you do not have access to your server
version.

You will have to edit the all_tests.php file if you are accesssing
the internet through a proxy server. See the comments in all_tests.php
for instructions.
with a custom php.ini file or with the switch -dmemory_limit=-1
if you do not have access to your server version.

The full tests read some test data from the LastCraft site. If the site
The full tests read some test data from simpletest.org. If the site
is down or has been modified for a later version then you will get
spurious errors. A unit_tests.php failure on the other hand would be
very serious. As far as we know we haven't yet managed to check in any
unit test failures so please correct us if you find one.
very serious. Please notify us if you find one.

Even if all of the tests run please verify that your existing test suites
also function as expected. If they don't see the file...
also function as expected. The file:

HELP_MY_TESTS_DONT_WORK_ANYMORE
HELP_MY_TESTS_DONT_WORK_ANYMORE

This contains information on interface changes. It also points out
deprecated interfaces so you should read this even if all of
...contains information on interface changes. It also points out
deprecated interfaces, so you should read this even if all of
your current tests appear to run.

There is a documentation folder which contains the core reference information
in English and French, although this information is fairly basic.
You can find a tutorial on...

http://www.lastcraft.com/first_test_tutorial.php
http://simpletest.org/en/first_test_tutorial.html

...to get you started and this material will eventually become included
with the project documentation. A French translation exists at...
with the project documentation. A French translation exists at:

http://www.onpk.net/index.php/2005/01/12/254-tutoriel-simpletest-decouvrir-les-tests-unitaires.
http://simpletest.org/fr/first_test_tutorial.html

If you download and use and possibly even extend this tool, please let us
If you download and use, and possibly even extend this tool, please let us
know. Any feedback, even bad, is always welcome and we will work to get
your suggestions into the next release. Ideally please send your
comments to...
comments to:

simpletest-support@lists.sourceforge.net
simpletest-support@lists.sourceforge.net

...so that others can read them too. We usually try to respond within 48
hours.

There is no change log as yet except at Sourceforge. You can visit the
There is no change log except at Sourceforge. You can visit the
release notes to see the completed TODO list after each cycle and also the
status of any bugs, but if the bug is recent then it will be fixed in CVS only.
The CVS check-ins always have all the tests passing and so CVS snapshots should
status of any bugs, but if the bug is recent then it will be fixed in SVN only.
The SVN check-ins always have all the tests passing and so SVN snapshots should
be pretty usable, although the code may not look so good internally.

Oh, yes. It is called "Simple" because it should be simple to
use. We intend to add a complete set of tools for a test first
and "test as you code" type of development. "Simple" does not
mean "Lite" in this context.
Oh, and one last thing: SimpleTest is called "Simple" because it should
be simple to use. We intend to add a complete set of tools for a test
first and "test as you code" type of development. "Simple" does not mean
"Lite" in this context.

Thanks to everyone who has sent comments and offered suggestions. They
really are invaluable, but sadly you are too many to mention in full.
Thanks to all on the advanced PHP forum on SitePoint, especially Harry
Feucks. Early adopters are always an inspiration.
Fuecks. Early adopters are always an inspiration.

yours Marcus Baker, Jason Sweat, Travis Swicegood and Perrick Penet.
--
marcus@lastcraft.com
-- Marcus Baker, Jason Sweat, Travis Swicegood, Perrick Penet and Edward Z. Yang.
2 changes: 1 addition & 1 deletion bouncer/tests/simpletest/VERSION 100644 → 100755
@@ -1 +1 @@
1.0.1beta2
1.1.0

0 comments on commit 03f65fb

Please sign in to comment.