Final subscriber with ORM.

This commit is contained in:
marco
2015-08-07 18:30:31 +02:00
parent 4378d42274
commit 5d7cbf136d
3 changed files with 52 additions and 9 deletions

View File

@@ -72,6 +72,12 @@ class RoboFile extends \Robo\Tasks {
$this->_exec('vendor/bin/codecept run'); $this->_exec('vendor/bin/codecept run');
} }
function testDebug() {
$this->_exec('vendor/bin/codecept build');
$this->loadEnv();
$this->_exec('vendor/bin/codecept run unit --debug');
}
protected function loadEnv() { protected function loadEnv() {
$dotenv = new Dotenv\Dotenv(__DIR__); $dotenv = new Dotenv\Dotenv(__DIR__);
$dotenv->load(); $dotenv->load();

View File

@@ -28,10 +28,10 @@ class Env {
public static function dbSourceName() { public static function dbSourceName() {
$source_name = array( $source_name = array(
'mysql:host=', 'mysql:host=',
Env::$db_host, DB_HOST,
';', ';',
'dbname=', 'dbname=',
Env::$db_name DB_NAME
); );
return implode('', $source_name); return implode('', $source_name);
} }

View File

@@ -1,19 +1,56 @@
<?php <?php
use \UnitTester; use \UnitTester;
use \MailPoet\Models\Subscriber;
class SubscriberCest { class SubscriberCest {
public function _before() { function _before() {
$this->subscriber = \Model::factory('Subscriber')->create(); $this->data = array(
$this->subscriber->first_name = 'John'; 'first_name' => 'John',
$this->subscriber->last_name = 'Mailer'; 'last_name' => 'Mailer',
$this->subscriber->email = 'john@mailpoet.com'; 'email' => 'john@mailpoet.com'
);
$this->subscriber = Subscriber::create();
$this
->subscriber
->first_name = $this->data['first_name'];
$this
->subscriber
->last_name = $this->data['last_name'];
$this->subscriber->email = $this->data['email'];
$this->subscriber->save(); $this->subscriber->save();
$this->id = $this->subscriber->id;
} }
public function itCanBeCreated() { function itCanBeCreated() {
$subscriber = Subscriber::where('first_name', $this->data['first_name'])->findOne();
expect($subscriber->id)->notNull();
} }
public function _after() { function itHasAFirstName() {
$subscriber = Subscriber::findOne($this->id);
expect($subscriber->first_name)
->equals($this->data['first_name']);
}
function itHasALastName() {
$subscriber = Subscriber::findOne($this->id);
expect($subscriber->last_name)
->equals($this->data['last_name']);
}
function itHasAnEmail() {
$subscriber = Subscriber::findOne($this->id);
expect($subscriber->email)
->equals($this->data['email']);
}
function _after() {
Subscriber::findOne($this->id)->delete();
} }
} }