Skip to content

Commit

Permalink
Update test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
rougin committed Oct 23, 2018
1 parent 0dd7d31 commit ada0698
Show file tree
Hide file tree
Showing 7 changed files with 200 additions and 67 deletions.
74 changes: 12 additions & 62 deletions tests/ModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@ class ModelTest extends \PHPUnit_Framework_TestCase
*/
public function setUp()
{
$app = (string) __DIR__ . '/Weblog';

$ci = Instance::create($app);
$ci = Instance::create(__DIR__ . '/Weblog');

$ci->load->helper('inflector');

$table = (string) singular($this->table);

$ci->load->model($table, '', true);

$ci->post->credo(new Credo($ci->db));

$this->ci = $ci;
}

Expand All @@ -65,52 +65,6 @@ public function testDeleteMethod()
$this->assertTrue(empty($post));
}

/**
* Tests Model::find.
*
* @return void
*/
public function testFindMethod()
{
list($id, $expected) = array(2, 'viG iJOzO');

$post = $this->ci->post->find((integer) $id);

$result = (string) $post->get_subject();

$this->assertEquals($expected, $result);
}

/**
* Tests Model::get.
*
* @return void
*/
public function testGetMethod()
{
$this->assertCount($this->rows, $this->ci->post->all());
}

/**
* Tests Model::paginate.
*
* @return void
*/
public function testPaginateMethod()
{
$config = array('page_query_string' => true);

$expected = (integer) 5;

$_GET['per_page'] = 1;

$config['use_page_numbers'] = true;

$result = $this->ci->post->paginate($expected, $config);

$this->assertCount($expected, $result[0]);
}

/**
* Tests Model::update.
*
Expand All @@ -132,31 +86,27 @@ public function testUpdateMethod()
}

/**
* Tests Model::validation.
* Tests Model::where.
*
* @return void
*/
public function testValidateMethod()
public function testWhereMethod()
{
$message = 'The Subject field is required.';

$expected = array('subject' => $message);

$this->ci->post->validate(array('message' => 'test'));

$result = $this->ci->post->validation_errors();
$this->ci->post->where('description', 'hdcgXrOKUD');

$this->assertEquals($expected, (array) $result);
$this->assertCount(1, $this->ci->post->get());
}

/**
* Tests Model::where.
* Tests Model::where with array as a parameter.
*
* @return void
*/
public function testWhereMethod()
public function testWhereWithArrayMethod()
{
$this->ci->post->where('description', 'hdcgXrOKUD');
$where = array('description' => 'hdcgXrOKUD');

$this->ci->post->where((array) $where);

$this->assertCount(1, $this->ci->post->get());
}
Expand Down
77 changes: 77 additions & 0 deletions tests/Traits/CredoTraitTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php

namespace Rougin\Credo;

use Rougin\SparkPlug\Instance;
use Rougin\Credo\Credo;

/**
* Credo Trait Test
*
* @package Credo
* @author Rougin Royce Gutib <rougingutib@gmail.com>
*/
class CredoTraitTest extends \PHPUnit_Framework_TestCase
{
/**
* @var \CI_Controller
*/
protected $ci;

/**
* @var integer
*/
protected $rows = 10;

/**
* Sets up the Codeigniter application.
*
* @return void
*/
public function setUp()
{
$path = (string) __DIR__ . '/Weblog';

$this->ci = Instance::create($path);

$this->ci->load->database();

$this->ci->load->model('post');
}

/**
* Tests CredoTrait::find.
*
* @return void
*/
public function testFindMethod()
{
list($id, $expected) = array(2, 'viG iJOzO');

$post = $this->ci->post->find((integer) $id);

$result = (string) $post->get_subject();

$this->assertEquals($expected, $result);
}

/**
* Tests CredoTrait::findBy.
*
* @return void
*/
public function testFindByMethod()
{
$this->assertCount($this->rows, $this->ci->post->findBy());
}

/**
* Tests CredoTrait::get.
*
* @return void
*/
public function testGetMethod()
{
$this->assertCount($this->rows, $this->ci->post->get());
}
}
55 changes: 55 additions & 0 deletions tests/Traits/PaginateTraitTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

namespace Rougin\Credo;

use Rougin\SparkPlug\Instance;

/**
* Paginate Trait Test
*
* @package Credo
* @author Rougin Royce Gutib <rougingutib@gmail.com>
*/
class PaginateTraitTest extends \PHPUnit_Framework_TestCase
{
/**
* @var \CI_Controller
*/
protected $ci;

/**
* Sets up the Codeigniter application.
*
* @return void
*/
public function setUp()
{
$path = (string) __DIR__ . '/Weblog';

$this->ci = Instance::create($path);

$this->ci->load->model('post');
}

/**
* Tests PaginateTrait::paginate.
*
* @return void
*/
public function testPaginateMethod()
{
$expected = (integer) 10;

$config = array('page_query_string' => true);

$config['use_page_numbers'] = true;

$_GET['per_page'] = (integer) 3;

$post = new \Post(array('user_id' => 1));

list($result) = $post->paginate(5, 20, $config);

$this->assertEquals($expected, $result);
}
}
51 changes: 51 additions & 0 deletions tests/Traits/ValidateTraitTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace Rougin\Credo;

use Rougin\SparkPlug\Instance;

/**
* Validate Trait Test
*
* @package Credo
* @author Rougin Royce Gutib <rougingutib@gmail.com>
*/
class ValidateTraitTest extends \PHPUnit_Framework_TestCase
{
/**
* @var \CI_Controller
*/
protected $ci;

/**
* Sets up the Codeigniter application.
*
* @return void
*/
public function setUp()
{
$path = (string) __DIR__ . '/Weblog';

$this->ci = Instance::create($path);

$this->ci->load->model('post');
}

/**
* Tests ValidateTrait::validate.
*
* @return void
*/
public function testValidateMethod()
{
$expected = array('subject' => 'The Subject field is required.');

$post = new \Post(array());

$post->validate(array('message' => 'test'));

$result = (array) $post->errors();

$this->assertEquals($expected, $result);
}
}
2 changes: 1 addition & 1 deletion tests/Weblog/application/models/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function get_subject()
*
* @var array
*/
protected $validation_rules = array(
protected $rules = array(
array('field' => 'subject', 'label' => 'Subject', 'rules' => 'required'),
);
}
4 changes: 2 additions & 2 deletions tests/Weblog/application/repositories/Post_repository.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

use Rougin\Credo\EntityRepository;
use Rougin\Credo\Repository;

class Post_repository extends EntityRepository
class Post_repository extends Repository
{
}
4 changes: 2 additions & 2 deletions tests/Weblog/application/repositories/User_repository.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

use Rougin\Credo\EntityRepository;
use Rougin\Credo\Repository;

class User_repository extends EntityRepository
class User_repository extends Repository
{
}

0 comments on commit ada0698

Please sign in to comment.