svn: /pear/packages/Mail_Queue/trunk/ Mail/Queue.php tests/Mail/QueueAbstract.php tests/Mail/QueueTest.php tests/TestInit.php tests/phpunit.xml
| From: | Till Klampaeckel | Date: | Wed, 29 Sep 2010 14:44:12 +0000 |
| Subject: | svn: /pear/packages/Mail_Queue/trunk/ Mail/Queue.php tests/Mail/QueueAbstract.php tests/Mail/QueueTest.php tests/TestInit.php tests/phpunit.xml | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-60416@lists.php.net to get a copy of this message | ||
till Wed, 29 Sep 2010 14:44:12 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=303857
Log:
* start working on test suite so we can move on Mail_Queue2 finally
Changed paths:
U pear/packages/Mail_Queue/trunk/Mail/Queue.php
A pear/packages/Mail_Queue/trunk/tests/
A pear/packages/Mail_Queue/trunk/tests/Mail/
A pear/packages/Mail_Queue/trunk/tests/Mail/QueueAbstract.php
A pear/packages/Mail_Queue/trunk/tests/Mail/QueueTest.php
A pear/packages/Mail_Queue/trunk/tests/TestInit.php
A pear/packages/Mail_Queue/trunk/tests/phpunit.xml
Modified: pear/packages/Mail_Queue/trunk/Mail/Queue.php
===================================================================
--- pear/packages/Mail_Queue/trunk/Mail/Queue.php 2010-09-29 13:49:11 UTC (rev 303856)
+++ pear/packages/Mail_Queue/trunk/Mail/Queue.php 2010-09-29 14:44:12 UTC (rev 303857)
@@ -167,6 +167,14 @@
var $_initErrors = array();
// }}}
+ // {{{ __construct
+
+ function __construct($container_options, $mail_options)
+ {
+ return $this->Mail_Queue($container_options, $mail_options);
+ }
+
+ // }}}
// {{{ Mail_Queue
/**
@@ -213,6 +221,9 @@
array_push($this->_initErrors, new
Mail_Queue_Error(MAILQUEUE_ERROR_UNKNOWN_CONTAINER,
$this->pearErrorMode, E_USER_ERROR, __FILE__, __LINE__));
} else {
+
+ unset($container_options['type']);
+
$this->container = new $container_class($container_options);
if(PEAR::isError($this->container)) {
array_push($this->_initErrors, new
Mail_Queue_Error(MAILQUEUE_ERROR_CANNOT_INITIALIZE,
Added: pear/packages/Mail_Queue/trunk/tests/Mail/QueueAbstract.php
===================================================================
--- pear/packages/Mail_Queue/trunk/tests/Mail/QueueAbstract.php (rev 0)
+++ pear/packages/Mail_Queue/trunk/tests/Mail/QueueAbstract.php 2010-09-29 14:44:12 UTC (rev 303857)
@@ -0,0 +1,113 @@
+<?php
+/**
+ * Base class for all tests.
+ */
+abstract class Mail_QueueAbstract extends PHPUnit_Framework_TestCase
+{
+ /**
+ * @var string $dsn String to connect to sqlite.
+ */
+ protected $dsn;
+
+ /**
+ * @var Mail_Queue $queue
+ */
+ protected $queue;
+
+ /**
+ * @var string $table The table name.
+ */
+ protected $table = 'mail_queue';
+
+ /**
+ * Initializes the Mail_Queue in {@link self::$queue}.
+ *
+ * @return void
+ * @uses MDB2_Driver_SQLite
+ */
+ public function setUp()
+ {
+ $this->dsn = 'sqlite:///' . __DIR__ .
'/mailqueueTestSuite?mode=0644';
+
+ $this->setUpDatabase();
+
+ $container_opts = array(
+ 'type' => 'mdb2',
+ 'dsn' => $this->dsn,
+ 'mail_table' => $this->table,
+ );
+
+ $mail_opts = array(
+ 'driver' => 'sendmail',
+ );
+
+ $this->queue = new Mail_Queue($container_opts, $mail_opts);
+ if ($this->queue->hasErrors()) {
+ $errors = $this->queue->getErrors();
+ $fail = "The following errors occurred:\n";
+ foreach ($errors as $error) {
+ $fail .= $error->getMessage() . "\n";
+ }
+ $this->fail($fail);
+ }
+ }
+
+ /**
+ * Remove the table/artifacts.
+ *
+ * @return void
+ * @see self::setUpDatabase()
+ */
+ public function tearDown()
+ {
+ $mdb2 = MDB2::connect($this->dsn);
+ $mdb2->query("DROP TABLE '{$this->table}'");
+ }
+
+ /**
+ * Create the table.
+ *
+ * @return void
+ * @see self::setUp()
+ * @see self::tearDown()
+ */
+ protected function setUpDatabase()
+ {
+ $mdb2 = MDB2::connect($this->dsn);
+ if (MDB2::isError($mdb2)) {
+ $this->fail($mdb2->getDebugInfo());
+ }
+
+ /**
+ * @desc An associative array with col/type and index.
+ */
+ $cols = array(
+ 'id INTEGER' => 'PRIMARY KEY',
+ 'create_time DATETIME' => '',
+ 'time_to_send DATETIME' => 'KEY',
+ 'sent_time DATETIME' => '',
+ 'id_user INTEGER' => 'KEY',
+ 'ip VARCHAR' => '',
+ 'sender VARCHAR' => '',
+ 'recipient TEXT' => '',
+ 'headers TEXT' => '',
+ 'body TEXT' => '',
+ 'try_sent INTEGER' => '',
+ 'delete_after_send INTEGER' => '',
+ );
+
+ $sql = "CREATE TABLE '{$this->table}' (";
+ foreach ($cols as $col => $idx) {
+ $sql .= trim("{$col} {$idx}");
+ $sql .= ',';
+ }
+ $sql = substr($sql, 0, -1) . ");";
+
+ $status = $mdb2->exec($sql);
+ if (MDB2::isError($status)) {
+ $this->fail($status->getDebugInfo());
+ }
+
+ $mdb2->disconnect();
+ }
+}
Added: pear/packages/Mail_Queue/trunk/tests/Mail/QueueTest.php
===================================================================
--- pear/packages/Mail_Queue/trunk/tests/Mail/QueueTest.php (rev 0)
+++ pear/packages/Mail_Queue/trunk/tests/Mail/QueueTest.php 2010-09-29 14:44:12 UTC (rev 303857)
@@ -0,0 +1,16 @@
+<?php
+/**
+ * So painful.
+ */
+class Mail_QueueTest extends Mail_QueueAbstract
+{
+ /**
+ * This should return a MDB2_Error
+ */
+ public function testSendMailByIdWithInvalidId()
+ {
+ $randomId = rand(0, 12);
+ $status = $this->queue->sendMailById($randomId);
+ $this->assertTrue(($status instanceof Mail_Queue_Error));
+ }
+}
Added: pear/packages/Mail_Queue/trunk/tests/TestInit.php
===================================================================
--- pear/packages/Mail_Queue/trunk/tests/TestInit.php (rev 0)
+++ pear/packages/Mail_Queue/trunk/tests/TestInit.php 2010-09-29 14:44:12 UTC (rev 303857)
@@ -0,0 +1,18 @@
+<?php
+// we run from within a checkout
+set_include_path(realpath(__DIR__ . '/../') . ':' . get_include_path());
+
+if (version_compare(PHP_VERSION, '5.3.0', '<')) {
+ echo "Sorry, you need 5.3.0+ to run this test suite.";
+ exit(1);
+}
+
+class TestInit
+{
+ public static function autoload($className)
+ {
+ $file = str_replace('_', '/', $className) . '.php';
+ return include $file;
+ }
+}
+spl_autoload_register(array('TestInit', 'autoload'));
Added: pear/packages/Mail_Queue/trunk/tests/phpunit.xml
===================================================================
--- pear/packages/Mail_Queue/trunk/tests/phpunit.xml (rev 0)
+++ pear/packages/Mail_Queue/trunk/tests/phpunit.xml 2010-09-29 14:44:12 UTC (rev 303857)
@@ -0,0 +1,5 @@
+<phpunit bootstrap="./TestInit.php" colors="true">
+ <testsuite name="Mail_Queue Test Suite">
+ <directory>./Mail</directory>
+ </testsuite>
+</phpunit>