diff --git a/lib/Validations.php b/lib/Validations.php index c2cec72b3..268ef8507 100644 --- a/lib/Validations.php +++ b/lib/Validations.php @@ -272,7 +272,7 @@ public function validates_inclusion_or_exclusion_of($type, $attrs) $enum = $options['within']; if (!is_array($enum)) - array($enum); + $enum = array($enum); $message = str_replace('%s', $var, $options['message']); diff --git a/test/ActiveRecordCacheTest.php b/test/ActiveRecordCacheTest.php index 6d43cca45..23e78bc35 100644 --- a/test/ActiveRecordCacheTest.php +++ b/test/ActiveRecordCacheTest.php @@ -3,7 +3,7 @@ class ActiveRecordCacheTest extends DatabaseTest { - public function set_up($connection_name=null) + public function setUp($connection_name=null) { if (!extension_loaded('memcache')) { @@ -11,11 +11,11 @@ public function set_up($connection_name=null) return; } - parent::set_up($connection_name); + parent::setUp($connection_name); ActiveRecord\Config::instance()->set_cache('memcache://localhost'); } - public function tear_down() + public function tearDown() { Cache::flush(); Cache::initialize(null); @@ -23,13 +23,13 @@ public function tear_down() public function test_default_expire() { - $this->assert_equals(30,Cache::$options['expire']); + $this->assertEquals(30,Cache::$options['expire']); } public function test_explicit_default_expire() { ActiveRecord\Config::instance()->set_cache('memcache://localhost',array('expire' => 1)); - $this->assert_equals(1,Cache::$options['expire']); + $this->assertEquals(1,Cache::$options['expire']); } public function test_caches_column_meta_data() @@ -38,7 +38,7 @@ public function test_caches_column_meta_data() $table_name = Author::table()->get_fully_qualified_table_name(!($this->conn instanceof ActiveRecord\PgsqlAdapter)); $value = Cache::$adapter->read("get_meta_data-$table_name"); - $this->assert_true(is_array($value)); + $this->assertTrue(is_array($value)); } } diff --git a/test/ActiveRecordFindTest.php b/test/ActiveRecordFindTest.php index b1e76a8ca..1ba18c060 100644 --- a/test/ActiveRecordFindTest.php +++ b/test/ActiveRecordFindTest.php @@ -13,7 +13,7 @@ public function test_find_with_no_params() public function test_find_by_pk() { $author = Author::find(3); - $this->assert_equals(3,$author->id); + $this->assertEquals(3,$author->id); } /** @@ -33,30 +33,30 @@ public function test_find_by_multiple_pk_with_partial_match() } catch (ActiveRecord\RecordNotFound $e) { - $this->assert_true(strpos($e->getMessage(),'found 1, but was looking for 2') !== false); + $this->assertTrue(strpos($e->getMessage(),'found 1, but was looking for 2') !== false); } } public function test_find_by_pk_with_options() { $author = Author::find(3,array('order' => 'name')); - $this->assert_equals(3,$author->id); - $this->assert_true(strpos(Author::table()->last_sql,'ORDER BY name') !== false); + $this->assertEquals(3,$author->id); + $this->assertTrue(strpos(Author::table()->last_sql,'ORDER BY name') !== false); } public function test_find_by_pk_array() { $authors = Author::find(1,'2'); - $this->assert_equals(2, count($authors)); - $this->assert_equals(1, $authors[0]->id); - $this->assert_equals(2, $authors[1]->id); + $this->assertEquals(2, count($authors)); + $this->assertEquals(1, $authors[0]->id); + $this->assertEquals(2, $authors[1]->id); } public function test_find_by_pk_array_with_options() { $authors = Author::find(1,'2',array('order' => 'name')); - $this->assert_equals(2, count($authors)); - $this->assert_true(strpos(Author::table()->last_sql,'ORDER BY name') !== false); + $this->assertEquals(2, count($authors)); + $this->assertTrue(strpos(Author::table()->last_sql,'ORDER BY name') !== false); } /** @@ -70,13 +70,13 @@ public function test_find_nothing_with_sql_in_string() public function test_find_all() { $authors = Author::find('all',array('conditions' => array('author_id IN(?)',array(1,2,3)))); - $this->assert_true(count($authors) >= 3); + $this->assertTrue(count($authors) >= 3); } public function test_find_all_with_no_bind_values() { $authors = Author::find('all',array('conditions' => array('author_id IN(1,2,3)'))); - $this->assert_equals(1,$authors[0]->author_id); + $this->assertEquals(1,$authors[0]->author_id); } /** @@ -91,112 +91,112 @@ public function test_find_all_with_empty_array_bind_value_throws_exception() public function test_find_hash_using_alias() { $venues = Venue::all(array('conditions' => array('marquee' => 'Warner Theatre', 'city' => array('Washington','New York')))); - $this->assert_true(count($venues) >= 1); + $this->assertTrue(count($venues) >= 1); } public function test_find_hash_using_alias_with_null() { $venues = Venue::all(array('conditions' => array('marquee' => null))); - $this->assert_equals(0,count($venues)); + $this->assertEquals(0,count($venues)); } public function test_dynamic_finder_using_alias() { - $this->assert_not_null(Venue::find_by_marquee('Warner Theatre')); + $this->assertNotNull(Venue::find_by_marquee('Warner Theatre')); } public function test_find_all_hash() { $books = Book::find('all',array('conditions' => array('author_id' => 1))); - $this->assert_true(count($books) > 0); + $this->assertTrue(count($books) > 0); } public function test_find_all_hash_with_order() { $books = Book::find('all',array('conditions' => array('author_id' => 1), 'order' => 'name DESC')); - $this->assert_true(count($books) > 0); + $this->assertTrue(count($books) > 0); } public function test_find_all_no_args() { $author = Author::all(); - $this->assert_true(count($author) > 1); + $this->assertTrue(count($author) > 1); } public function test_find_all_no_results() { $authors = Author::find('all',array('conditions' => array('author_id IN(11111111111,22222222222,333333333333)'))); - $this->assert_equals(array(),$authors); + $this->assertEquals(array(),$authors); } public function test_find_first() { $author = Author::find('first',array('conditions' => array('author_id IN(?)', array(1,2,3)))); - $this->assert_equals(1,$author->author_id); - $this->assert_equals('Tito',$author->name); + $this->assertEquals(1,$author->author_id); + $this->assertEquals('Tito',$author->name); } public function test_find_first_no_results() { - $this->assert_null(Author::find('first',array('conditions' => 'author_id=1111111'))); + $this->assertNull(Author::find('first',array('conditions' => 'author_id=1111111'))); } public function test_find_first_using_pk() { $author = Author::find('first',3); - $this->assert_equals(3,$author->author_id); + $this->assertEquals(3,$author->author_id); } public function test_find_first_with_conditions_as_string() { $author = Author::find('first',array('conditions' => 'author_id=3')); - $this->assert_equals(3,$author->author_id); + $this->assertEquals(3,$author->author_id); } public function test_find_all_with_conditions_as_string() { $author = Author::find('all',array('conditions' => 'author_id in(2,3)')); - $this->assert_equals(2,count($author)); + $this->assertEquals(2,count($author)); } public function test_find_by_sql() { $author = Author::find_by_sql("SELECT * FROM authors WHERE author_id in(1,2)"); - $this->assert_equals(1,$author[0]->author_id); - $this->assert_equals(2,count($author)); + $this->assertEquals(1,$author[0]->author_id); + $this->assertEquals(2,count($author)); } public function test_find_by_sqltakes_values_array() { $author = Author::find_by_sql("SELECT * FROM authors WHERE author_id=?",array(1)); - $this->assert_not_null($author); + $this->assertNotNull($author); } public function test_find_with_conditions() { $author = Author::find(array('conditions' => array('author_id=? and name=?', 1, 'Tito'))); - $this->assert_equals(1,$author->author_id); + $this->assertEquals(1,$author->author_id); } public function test_find_last() { $author = Author::last(); - $this->assert_equals(4, $author->author_id); - $this->assert_equals('Uncle Bob',$author->name); + $this->assertEquals(4, $author->author_id); + $this->assertEquals('Uncle Bob',$author->name); } public function test_find_last_using_string_condition() { $author = Author::find('last', array('conditions' => 'author_id IN(1,2,3,4)')); - $this->assert_equals(4, $author->author_id); - $this->assert_equals('Uncle Bob',$author->name); + $this->assertEquals(4, $author->author_id); + $this->assertEquals('Uncle Bob',$author->name); } public function test_limit_before_order() { $authors = Author::all(array('limit' => 2, 'order' => 'author_id desc', 'conditions' => 'author_id in(1,2)')); - $this->assert_equals(2,$authors[0]->author_id); - $this->assert_equals(1,$authors[1]->author_id); + $this->assertEquals(2,$authors[0]->author_id); + $this->assertEquals(1,$authors[1]->author_id); } public function test_for_each() @@ -206,10 +206,10 @@ public function test_for_each() foreach ($res as $author) { - $this->assert_true($author instanceof ActiveRecord\Model); + $this->assertTrue($author instanceof ActiveRecord\Model); $i++; } - $this->assert_true($i > 0); + $this->assertTrue($i > 0); } public function test_fetch_all() @@ -218,50 +218,50 @@ public function test_fetch_all() foreach (Author::all() as $author) { - $this->assert_true($author instanceof ActiveRecord\Model); + $this->assertTrue($author instanceof ActiveRecord\Model); $i++; } - $this->assert_true($i > 0); + $this->assertTrue($i > 0); } public function test_count() { - $this->assert_same(1,Author::count(1)); - $this->assert_same(2,Author::count(array(1,2))); - $this->assert_true(Author::count() > 1); - $this->assert_same(0,Author::count(array('conditions' => 'author_id=99999999999999'))); - $this->assert_same(2,Author::count(array('conditions' => 'author_id=1 or author_id=2'))); - $this->assert_same(1,Author::count(array('name' => 'Tito', 'author_id' => 1))); + $this->assertSame(1,Author::count(1)); + $this->assertSame(2,Author::count(array(1,2))); + $this->assertTrue(Author::count() > 1); + $this->assertSame(0,Author::count(array('conditions' => 'author_id=99999999999999'))); + $this->assertSame(2,Author::count(array('conditions' => 'author_id=1 or author_id=2'))); + $this->assertSame(1,Author::count(array('name' => 'Tito', 'author_id' => 1))); } public function test_gh149_empty_count() { $total = Author::count(); - $this->assert_equals($total, Author::count(null)); - $this->assert_equals($total, Author::count(array())); + $this->assertEquals($total, Author::count(null)); + $this->assertEquals($total, Author::count(array())); } public function test_exists() { - $this->assert_true(Author::exists(1)); - $this->assert_true(Author::exists(array('conditions' => 'author_id=1'))); - $this->assert_true(Author::exists(array('conditions' => array('author_id=? and name=?', 1, 'Tito')))); - $this->assert_false(Author::exists(9999999)); - $this->assert_false(Author::exists(array('conditions' => 'author_id=999999'))); + $this->assertTrue(Author::exists(1)); + $this->assertTrue(Author::exists(array('conditions' => 'author_id=1'))); + $this->assertTrue(Author::exists(array('conditions' => array('author_id=? and name=?', 1, 'Tito')))); + $this->assertFalse(Author::exists(9999999)); + $this->assertFalse(Author::exists(array('conditions' => 'author_id=999999'))); } public function test_find_by_call_static() { - $this->assert_equals('Tito',Author::find_by_name('Tito')->name); - $this->assert_equals('Tito',Author::find_by_author_id_and_name(1,'Tito')->name); - $this->assert_equals('George W. Bush',Author::find_by_author_id_or_name(2,'Tito',array('order' => 'author_id desc'))->name); - $this->assert_equals('Tito',Author::find_by_name(array('Tito','George W. Bush'),array('order' => 'name desc'))->name); + $this->assertEquals('Tito',Author::find_by_name('Tito')->name); + $this->assertEquals('Tito',Author::find_by_author_id_and_name(1,'Tito')->name); + $this->assertEquals('George W. Bush',Author::find_by_author_id_or_name(2,'Tito',array('order' => 'author_id desc'))->name); + $this->assertEquals('Tito',Author::find_by_name(array('Tito','George W. Bush'),array('order' => 'name desc'))->name); } public function test_find_by_call_static_no_results() { - $this->assert_null(Author::find_by_name('SHARKS WIT LASERZ')); - $this->assert_null(Author::find_by_name_or_author_id()); + $this->assertNull(Author::find_by_name('SHARKS WIT LASERZ')); + $this->assertNull(Author::find_by_name_or_author_id()); } /** @@ -275,25 +275,25 @@ public function test_find_by_call_static_invalid_column_name() public function test_find_all_by_call_static() { $x = Author::find_all_by_name('Tito'); - $this->assert_equals('Tito',$x[0]->name); - $this->assert_equals(1,count($x)); + $this->assertEquals('Tito',$x[0]->name); + $this->assertEquals(1,count($x)); $x = Author::find_all_by_author_id_or_name(2,'Tito',array('order' => 'name asc')); - $this->assert_equals(2,count($x)); - $this->assert_equals('George W. Bush',$x[0]->name); + $this->assertEquals(2,count($x)); + $this->assertEquals('George W. Bush',$x[0]->name); } public function test_find_all_by_call_static_no_results() { $x = Author::find_all_by_name('SHARKSSSSSSS'); - $this->assert_equals(0,count($x)); + $this->assertEquals(0,count($x)); } public function test_find_all_by_call_static_with_array_values_and_options() { $author = Author::find_all_by_name(array('Tito','Bill Clinton'),array('order' => 'name desc')); - $this->assert_equals('Tito',$author[0]->name); - $this->assert_equals('Bill Clinton',$author[1]->name); + $this->assertEquals('Tito',$author[0]->name); + $this->assertEquals('Bill Clinton',$author[1]->name); } /** @@ -307,7 +307,7 @@ public function test_find_all_by_call_static_undefined_method() public function test_find_all_takes_limit_options() { $authors = Author::all(array('limit' => 1, 'offset' => 2, 'order' => 'name desc')); - $this->assert_equals('George W. Bush',$authors[0]->name); + $this->assertEquals('George W. Bush',$authors[0]->name); } /** @@ -321,8 +321,8 @@ public function test_find_by_call_static_with_invalid_field_name() public function test_find_with_select() { $author = Author::first(array('select' => 'name, 123 as bubba', 'order' => 'name desc')); - $this->assert_equals('Uncle Bob',$author->name); - $this->assert_equals(123,$author->bubba); + $this->assertEquals('Uncle Bob',$author->name); + $this->assertEquals(123,$author->bubba); } public function test_find_with_select_non_selected_fields_should_not_have_attributes() @@ -340,45 +340,45 @@ public function test_joins_on_model_with_association_and_explicit_joins() { JoinBook::$belongs_to = array(array('author')); JoinBook::first(array('joins' => array('author','LEFT JOIN authors a ON(books.secondary_author_id=a.author_id)'))); - $this->assert_sql_has('INNER JOIN authors ON(books.author_id = authors.author_id)',JoinBook::table()->last_sql); - $this->assert_sql_has('LEFT JOIN authors a ON(books.secondary_author_id=a.author_id)',JoinBook::table()->last_sql); + $this->assertSqlHas('INNER JOIN authors ON(books.author_id = authors.author_id)',JoinBook::table()->last_sql); + $this->assertSqlHas('LEFT JOIN authors a ON(books.secondary_author_id=a.author_id)',JoinBook::table()->last_sql); } public function test_joins_on_model_with_explicit_joins() { JoinBook::first(array('joins' => array('LEFT JOIN authors a ON(books.secondary_author_id=a.author_id)'))); - $this->assert_sql_has('LEFT JOIN authors a ON(books.secondary_author_id=a.author_id)',JoinBook::table()->last_sql); + $this->assertSqlHas('LEFT JOIN authors a ON(books.secondary_author_id=a.author_id)',JoinBook::table()->last_sql); } public function test_group() { $venues = Venue::all(array('select' => 'state', 'group' => 'state')); - $this->assert_true(count($venues) > 0); - $this->assert_sql_has('GROUP BY state',ActiveRecord\Table::load('Venue')->last_sql); + $this->assertTrue(count($venues) > 0); + $this->assertSqlHas('GROUP BY state',ActiveRecord\Table::load('Venue')->last_sql); } public function test_group_with_order_and_limit_and_having() { $venues = Venue::all(array('select' => 'state', 'group' => 'state', 'having' => 'length(state) = 2', 'order' => 'state', 'limit' => 2)); - $this->assert_true(count($venues) > 0); - $this->assert_sql_has($this->conn->limit('SELECT state FROM venues GROUP BY state HAVING length(state) = 2 ORDER BY state',null,2),Venue::table()->last_sql); + $this->assertTrue(count($venues) > 0); + $this->assertSqlHas($this->conn->limit('SELECT state FROM venues GROUP BY state HAVING length(state) = 2 ORDER BY state',null,2),Venue::table()->last_sql); } public function test_escape_quotes() { $author = Author::find_by_name("Tito's"); - $this->assert_not_equals("Tito's",Author::table()->last_sql); + $this->assertNotEquals("Tito's",Author::table()->last_sql); } public function test_from() { $author = Author::find('first', array('from' => 'books', 'order' => 'author_id asc')); - $this->assert_true($author instanceof Author); - $this->assert_not_null($author->book_id); + $this->assertTrue($author instanceof Author); + $this->assertNotNull($author->book_id); $author = Author::find('first', array('from' => 'authors', 'order' => 'author_id asc')); - $this->assert_true($author instanceof Author); - $this->assert_equals(1, $author->id); + $this->assertTrue($author instanceof Author); + $this->assertEquals(1, $author->id); } public function test_having() @@ -389,7 +389,7 @@ public function test_having() 'select' => 'to_char(created_at,\'YYYY-MM-DD\') as created_at', 'group' => 'to_char(created_at,\'YYYY-MM-DD\')', 'having' => "to_char(created_at,'YYYY-MM-DD') > '2009-01-01'")); - $this->assert_sql_has("GROUP BY to_char(created_at,'YYYY-MM-DD') HAVING to_char(created_at,'YYYY-MM-DD') > '2009-01-01'",Author::table()->last_sql); + $this->assertSqlHas("GROUP BY to_char(created_at,'YYYY-MM-DD') HAVING to_char(created_at,'YYYY-MM-DD') > '2009-01-01'",Author::table()->last_sql); } else { @@ -397,7 +397,7 @@ public function test_having() 'select' => 'date(created_at) as created_at', 'group' => 'date(created_at)', 'having' => "date(created_at) > '2009-01-01'")); - $this->assert_sql_has("GROUP BY date(created_at) HAVING date(created_at) > '2009-01-01'",Author::table()->last_sql); + $this->assertSqlHas("GROUP BY date(created_at) HAVING date(created_at) > '2009-01-01'",Author::table()->last_sql); } } @@ -411,22 +411,22 @@ public function test_from_with_invalid_table() public function test_find_with_hash() { - $this->assert_not_null(Author::find(array('name' => 'Tito'))); - $this->assert_not_null(Author::find('first',array('name' => 'Tito'))); - $this->assert_equals(1,count(Author::find('all',array('name' => 'Tito')))); - $this->assert_equals(1,count(Author::all(array('name' => 'Tito')))); + $this->assertNotNull(Author::find(array('name' => 'Tito'))); + $this->assertNotNull(Author::find('first',array('name' => 'Tito'))); + $this->assertEquals(1,count(Author::find('all',array('name' => 'Tito')))); + $this->assertEquals(1,count(Author::all(array('name' => 'Tito')))); } public function test_find_or_create_by_on_existing_record() { - $this->assert_not_null(Author::find_or_create_by_name('Tito')); + $this->assertNotNull(Author::find_or_create_by_name('Tito')); } public function test_find_or_create_by_creates_new_record() { $author = Author::find_or_create_by_name_and_encrypted_password('New Guy','pencil'); - $this->assert_true($author->author_id > 0); - $this->assert_equals('pencil',$author->encrypted_password); + $this->assertTrue($author->author_id > 0); + $this->assertEquals('pencil',$author->encrypted_password); } /** @@ -455,15 +455,15 @@ public function test_find_by_null() public function test_count_by() { - $this->assert_equals(2,Venue::count_by_state('VA')); - $this->assert_equals(3,Venue::count_by_state_or_name('VA','Warner Theatre')); - $this->assert_equals(0,Venue::count_by_state_and_name('VA','zzzzzzzzzzzzz')); + $this->assertEquals(2,Venue::count_by_state('VA')); + $this->assertEquals(3,Venue::count_by_state_or_name('VA','Warner Theatre')); + $this->assertEquals(0,Venue::count_by_state_and_name('VA','zzzzzzzzzzzzz')); } public function test_find_by_pk_should_not_use_limit() { Author::find(1); - $this->assert_sql_has('SELECT * FROM authors WHERE author_id=?',Author::table()->last_sql); + $this->assertSqlHas('SELECT * FROM authors WHERE author_id=?',Author::table()->last_sql); } public function test_find_by_datetime() @@ -473,7 +473,7 @@ public function test_find_by_datetime() $arnow->setTimestamp($now->getTimestamp()); Author::find(1)->update_attribute('created_at',$now); - $this->assert_not_null(Author::find_by_created_at($now)); - $this->assert_not_null(Author::find_by_created_at($arnow)); + $this->assertNotNull(Author::find_by_created_at($now)); + $this->assertNotNull(Author::find_by_created_at($arnow)); } } diff --git a/test/ActiveRecordTest.php b/test/ActiveRecordTest.php index cc0eaf881..c1bac851e 100644 --- a/test/ActiveRecordTest.php +++ b/test/ActiveRecordTest.php @@ -2,59 +2,59 @@ class ActiveRecordTest extends DatabaseTest { - public function set_up($connection_name=null) + public function setUp($connection_name=null) { - parent::set_up($connection_name); + parent::setUp($connection_name); $this->options = array('conditions' => 'blah', 'order' => 'blah'); } public function test_options_is_not() { - $this->assert_false(Author::is_options_hash(null)); - $this->assert_false(Author::is_options_hash('')); - $this->assert_false(Author::is_options_hash('tito')); - $this->assert_false(Author::is_options_hash(array())); - $this->assert_false(Author::is_options_hash(array(1,2,3))); + $this->assertFalse(Author::is_options_hash(null)); + $this->assertFalse(Author::is_options_hash('')); + $this->assertFalse(Author::is_options_hash('tito')); + $this->assertFalse(Author::is_options_hash(array())); + $this->assertFalse(Author::is_options_hash(array(1,2,3))); } /** * @expectedException ActiveRecord\ActiveRecordException */ public function test_options_hash_with_unknown_keys() { - $this->assert_false(Author::is_options_hash(array('conditions' => 'blah', 'sharks' => 'laserz', 'dubya' => 'bush'))); + $this->assertFalse(Author::is_options_hash(array('conditions' => 'blah', 'sharks' => 'laserz', 'dubya' => 'bush'))); } public function test_options_is_hash() { - $this->assert_true(Author::is_options_hash($this->options)); + $this->assertTrue(Author::is_options_hash($this->options)); } public function test_extract_and_validate_options() { $args = array('first',$this->options); - $this->assert_equals($this->options,Author::extract_and_validate_options($args)); - $this->assert_equals(array('first'),$args); + $this->assertEquals($this->options,Author::extract_and_validate_options($args)); + $this->assertEquals(array('first'),$args); } public function test_extract_and_validate_options_with_array_in_args() { $args = array('first',array(1,2),$this->options); - $this->assert_equals($this->options,Author::extract_and_validate_options($args)); + $this->assertEquals($this->options,Author::extract_and_validate_options($args)); } public function test_extract_and_validate_options_removes_options_hash() { $args = array('first',$this->options); Author::extract_and_validate_options($args); - $this->assert_equals(array('first'),$args); + $this->assertEquals(array('first'),$args); } public function test_extract_and_validate_options_nope() { $args = array('first'); - $this->assert_equals(array(),Author::extract_and_validate_options($args)); - $this->assert_equals(array('first'),$args); + $this->assertEquals(array(),Author::extract_and_validate_options($args)); + $this->assertEquals(array('first'),$args); } public function test_extract_and_validate_options_nope_because_wasnt_at_end() { $args = array('first',$this->options,array(1,2)); - $this->assert_equals(array(),Author::extract_and_validate_options($args)); + $this->assertEquals(array(),Author::extract_and_validate_options($args)); } /** @@ -75,13 +75,13 @@ public function test_invalid_attributes() $exceptions = explode("\r\n", $e->getMessage()); } - $this->assert_equals(1, substr_count($exceptions[0], 'invalid_attribute')); - $this->assert_equals(1, substr_count($exceptions[1], 'another_invalid_attribute')); + $this->assertEquals(1, substr_count($exceptions[0], 'invalid_attribute')); + $this->assertEquals(1, substr_count($exceptions[1], 'another_invalid_attribute')); } public function test_getter_undefined_property_exception_includes_model_name() { - $this->assert_exception_message_contains("Author->this_better_not_exist",function() + $this->assertExceptionMessageContains("Author->this_better_not_exist",function() { $author = new Author(); $author->this_better_not_exist; @@ -90,7 +90,7 @@ public function test_getter_undefined_property_exception_includes_model_name() public function test_mass_assignment_undefined_property_exception_includes_model_name() { - $this->assert_exception_message_contains("Author->this_better_not_exist",function() + $this->assertExceptionMessageContains("Author->this_better_not_exist",function() { new Author(array("this_better_not_exist" => "hi")); }); @@ -98,7 +98,7 @@ public function test_mass_assignment_undefined_property_exception_includes_model public function test_setter_undefined_property_exception_includes_model_name() { - $this->assert_exception_message_contains("Author->this_better_not_exist",function() + $this->assertExceptionMessageContains("Author->this_better_not_exist",function() { $author = new Author(); $author->this_better_not_exist = "hi"; @@ -109,8 +109,8 @@ public function test_get_values_for() { $book = Book::find_by_name('Ancient Art of Main Tanking'); $ret = $book->get_values_for(array('book_id','author_id')); - $this->assert_equals(array('book_id','author_id'),array_keys($ret)); - $this->assert_equals(array(1,1),array_values($ret)); + $this->assertEquals(array('book_id','author_id'),array_keys($ret)); + $this->assertEquals(array(1,1),array_values($ret)); } public function test_hyphenated_column_names_to_underscore() @@ -119,7 +119,7 @@ public function test_hyphenated_column_names_to_underscore() return; $keys = array_keys(RmBldg::first()->attributes()); - $this->assert_true(in_array('rm_name',$keys)); + $this->assertTrue(in_array('rm_name',$keys)); } public function test_column_names_with_spaces() @@ -128,13 +128,13 @@ public function test_column_names_with_spaces() return; $keys = array_keys(RmBldg::first()->attributes()); - $this->assert_true(in_array('space_out',$keys)); + $this->assertTrue(in_array('space_out',$keys)); } public function test_mixed_case_column_name() { $keys = array_keys(Author::first()->attributes()); - $this->assert_true(in_array('mixedcasefield',$keys)); + $this->assertTrue(in_array('mixedcasefield',$keys)); } public function test_mixed_case_primary_key_save() @@ -142,17 +142,17 @@ public function test_mixed_case_primary_key_save() $venue = Venue::find(1); $venue->name = 'should not throw exception'; $venue->save(); - $this->assert_equals($venue->name,Venue::find(1)->name); + $this->assertEquals($venue->name,Venue::find(1)->name); } public function test_reload() { $venue = Venue::find(1); - $this->assert_equals('NY', $venue->state); + $this->assertEquals('NY', $venue->state); $venue->state = 'VA'; - $this->assert_equals('VA', $venue->state); + $this->assertEquals('VA', $venue->state); $venue->reload(); - $this->assert_equals('NY', $venue->state); + $this->assertEquals('NY', $venue->state); } public function test_reload_protected_attribute() @@ -161,14 +161,14 @@ public function test_reload_protected_attribute() $book->name = "Should not stay"; $book->reload(); - $this->assert_not_equals("Should not stay", $book->name); + $this->assertNotEquals("Should not stay", $book->name); } public function test_active_record_model_home_not_set() { $home = ActiveRecord\Config::instance()->get_model_directory(); ActiveRecord\Config::instance()->set_model_directory(__DIR__); - $this->assert_equals(false,class_exists('TestAutoload')); + $this->assertEquals(false,class_exists('TestAutoload')); ActiveRecord\Config::instance()->set_model_directory($home); } @@ -179,14 +179,14 @@ public function test_auto_load_with_model_in_secondary_model_directory(){ realpath(__DIR__ . '/models'), realpath(__DIR__ . '/backup-models'), )); - $this->assert_true(class_exists('Backup')); + $this->assertTrue(class_exists('Backup')); ActiveRecord\Config::instance()->set_model_directory($home); } public function test_auto_load_with_namespaced_model() { - $this->assert_true(class_exists('NamespaceTest\Book')); + $this->assertTrue(class_exists('NamespaceTest\Book')); } public function test_auto_load_with_namespaced_model_in_secondary_model_directory(){ @@ -195,7 +195,7 @@ public function test_auto_load_with_namespaced_model_in_secondary_model_director realpath(__DIR__ . '/models'), realpath(__DIR__ . '/backup-models'), )); - $this->assert_true(class_exists('NamespaceTest\Backup')); + $this->assertTrue(class_exists('NamespaceTest\Backup')); ActiveRecord\Config::instance()->set_model_directory($home); } @@ -203,7 +203,7 @@ public function test_auto_load_with_namespaced_model_in_secondary_model_director public function test_namespace_gets_stripped_from_table_name() { $model = new NamespaceTest\Book(); - $this->assert_equals('books',$model->table()->table); + $this->assertEquals('books',$model->table()->table); } public function test_namespace_gets_stripped_from_inferred_foreign_key() @@ -211,9 +211,9 @@ public function test_namespace_gets_stripped_from_inferred_foreign_key() $model = new NamespaceTest\Book(); $table = ActiveRecord\Table::load(get_class($model)); - $this->assert_equals($table->get_relationship('parent_book')->foreign_key[0], 'book_id'); - $this->assert_equals($table->get_relationship('parent_book_2')->foreign_key[0], 'book_id'); - $this->assert_equals($table->get_relationship('parent_book_3')->foreign_key[0], 'book_id'); + $this->assertEquals($table->get_relationship('parent_book')->foreign_key[0], 'book_id'); + $this->assertEquals($table->get_relationship('parent_book_2')->foreign_key[0], 'book_id'); + $this->assertEquals($table->get_relationship('parent_book_3')->foreign_key[0], 'book_id'); } public function test_namespaced_relationship_associates_correctly() @@ -221,30 +221,30 @@ public function test_namespaced_relationship_associates_correctly() $model = new NamespaceTest\Book(); $table = ActiveRecord\Table::load(get_class($model)); - $this->assert_not_null($table->get_relationship('parent_book')); - $this->assert_not_null($table->get_relationship('parent_book_2')); - $this->assert_not_null($table->get_relationship('parent_book_3')); + $this->assertNotNull($table->get_relationship('parent_book')); + $this->assertNotNull($table->get_relationship('parent_book_2')); + $this->assertNotNull($table->get_relationship('parent_book_3')); - $this->assert_not_null($table->get_relationship('pages')); - $this->assert_not_null($table->get_relationship('pages_2')); + $this->assertNotNull($table->get_relationship('pages')); + $this->assertNotNull($table->get_relationship('pages_2')); - $this->assert_null($table->get_relationship('parent_book_4')); - $this->assert_null($table->get_relationship('pages_3')); + $this->assertNull($table->get_relationship('parent_book_4')); + $this->assertNull($table->get_relationship('pages_3')); // Should refer to the same class - $this->assert_same( + $this->assertSame( ltrim($table->get_relationship('parent_book')->class_name, '\\'), ltrim($table->get_relationship('parent_book_2')->class_name, '\\') ); // Should refer to different classes - $this->assert_not_same( + $this->assertNotSame( ltrim($table->get_relationship('parent_book_2')->class_name, '\\'), ltrim($table->get_relationship('parent_book_3')->class_name, '\\') ); // Should refer to the same class - $this->assert_same( + $this->assertSame( ltrim($table->get_relationship('pages')->class_name, '\\'), ltrim($table->get_relationship('pages_2')->class_name, '\\') ); @@ -253,32 +253,32 @@ public function test_namespaced_relationship_associates_correctly() public function test_should_have_all_column_attributes_when_initializing_with_array() { $author = new Author(array('name' => 'Tito')); - $this->assert_true(count(array_keys($author->attributes())) >= 9); + $this->assertTrue(count(array_keys($author->attributes())) >= 9); } public function test_defaults() { $author = new Author(); - $this->assert_equals('default_name',$author->name); + $this->assertEquals('default_name',$author->name); } public function test_alias_attribute_getter() { $venue = Venue::find(1); - $this->assert_equals($venue->marquee, $venue->name); - $this->assert_equals($venue->mycity, $venue->city); + $this->assertEquals($venue->marquee, $venue->name); + $this->assertEquals($venue->mycity, $venue->city); } public function test_alias_attribute_setter() { $venue = Venue::find(1); $venue->marquee = 'new name'; - $this->assert_equals($venue->marquee, 'new name'); - $this->assert_equals($venue->marquee, $venue->name); + $this->assertEquals($venue->marquee, 'new name'); + $this->assertEquals($venue->marquee, $venue->name); $venue->name = 'another name'; - $this->assert_equals($venue->name, 'another name'); - $this->assert_equals($venue->marquee, $venue->name); + $this->assertEquals($venue->name, 'another name'); + $this->assertEquals($venue->marquee, $venue->name); } public function test_alias_attribute_custom_setter() @@ -287,12 +287,12 @@ public function test_alias_attribute_custom_setter() $venue = Venue::find(1); $venue->mycity = 'cityname'; - $this->assert_equals($venue->mycity, 'cityname#'); - $this->assert_equals($venue->mycity, $venue->city); + $this->assertEquals($venue->mycity, 'cityname#'); + $this->assertEquals($venue->mycity, $venue->city); $venue->city = 'anothercity'; - $this->assert_equals($venue->city, 'anothercity#'); - $this->assert_equals($venue->city, $venue->mycity); + $this->assertEquals($venue->city, 'anothercity#'); + $this->assertEquals($venue->city, $venue->mycity); Venue::$use_custom_set_city_setter = false; } @@ -300,43 +300,43 @@ public function test_alias_attribute_custom_setter() public function test_alias_from_mass_attributes() { $venue = new Venue(array('marquee' => 'meme', 'id' => 123)); - $this->assert_equals('meme',$venue->name); - $this->assert_equals($venue->marquee,$venue->name); + $this->assertEquals('meme',$venue->name); + $this->assertEquals($venue->marquee,$venue->name); } public function test_gh18_isset_on_aliased_attribute() { - $this->assert_true(isset(Venue::first()->marquee)); + $this->assertTrue(isset(Venue::first()->marquee)); } public function test_attr_accessible() { $book = new BookAttrAccessible(array('name' => 'should not be set', 'author_id' => 1)); - $this->assert_null($book->name); - $this->assert_equals(1,$book->author_id); + $this->assertNull($book->name); + $this->assertEquals(1,$book->author_id); $book->name = 'test'; - $this->assert_equals('test', $book->name); + $this->assertEquals('test', $book->name); } public function test_attr_protected() { $book = new BookAttrAccessible(array('book_id' => 999)); - $this->assert_null($book->book_id); + $this->assertNull($book->book_id); $book->book_id = 999; - $this->assert_equals(999, $book->book_id); + $this->assertEquals(999, $book->book_id); } public function test_isset() { $book = new Book(); - $this->assert_true(isset($book->name)); - $this->assert_false(isset($book->sharks)); + $this->assertTrue(isset($book->name)); + $this->assertFalse(isset($book->sharks)); } public function test_readonly_only_halt_on_write_method() { $book = Book::first(array('readonly' => true)); - $this->assert_true($book->is_readonly()); + $this->assertTrue($book->is_readonly()); try { $book->save(); @@ -345,43 +345,43 @@ public function test_readonly_only_halt_on_write_method() } $book->name = 'some new name'; - $this->assert_equals($book->name, 'some new name'); + $this->assertEquals($book->name, 'some new name'); } public function test_cast_when_using_setter() { $book = new Book(); $book->book_id = '1'; - $this->assert_same(1,$book->book_id); + $this->assertSame(1,$book->book_id); } public function test_cast_when_loading() { $book = Book::find(1); - $this->assert_same(1,$book->book_id); - $this->assert_same('Ancient Art of Main Tanking',$book->name); + $this->assertSame(1,$book->book_id); + $this->assertSame('Ancient Art of Main Tanking',$book->name); } public function test_cast_defaults() { $book = new Book(); - $this->assert_same(0.0,$book->special); + $this->assertSame(0.0,$book->special); } public function test_transaction_committed() { $original = Author::count(); $ret = Author::transaction(function() { Author::create(array("name" => "blah")); }); - $this->assert_equals($original+1,Author::count()); - $this->assert_true($ret); + $this->assertEquals($original+1,Author::count()); + $this->assertTrue($ret); } public function test_transaction_committed_when_returning_true() { $original = Author::count(); $ret = Author::transaction(function() { Author::create(array("name" => "blah")); return true; }); - $this->assert_equals($original+1,Author::count()); - $this->assert_true($ret); + $this->assertEquals($original+1,Author::count()); + $this->assertTrue($ret); } public function test_transaction_rolledback_by_returning_false() @@ -394,8 +394,8 @@ public function test_transaction_rolledback_by_returning_false() return false; }); - $this->assert_equals($original,Author::count()); - $this->assert_false($ret); + $this->assertEquals($original,Author::count()); + $this->assertFalse($ret); } public function test_transaction_rolledback_by_throwing_exception() @@ -416,34 +416,34 @@ public function test_transaction_rolledback_by_throwing_exception() $exception = $e; } - $this->assert_not_null($exception); - $this->assert_equals($original,Author::count()); + $this->assertNotNull($exception); + $this->assertEquals($original,Author::count()); } public function test_delegate() { $event = Event::first(); - $this->assert_equals($event->venue->state,$event->state); - $this->assert_equals($event->venue->address,$event->address); + $this->assertEquals($event->venue->state,$event->state); + $this->assertEquals($event->venue->address,$event->address); } public function test_delegate_prefix() { $event = Event::first(); - $this->assert_equals($event->host->name,$event->woot_name); + $this->assertEquals($event->host->name,$event->woot_name); } public function test_delegate_returns_null_if_relationship_does_not_exist() { $event = new Event(); - $this->assert_null($event->state); + $this->assertNull($event->state); } public function test_delegate_set_attribute() { $event = Event::first(); $event->state = 'MEXICO'; - $this->assert_equals('MEXICO',$event->venue->state); + $this->assertEquals('MEXICO',$event->venue->state); } public function test_delegate_getter_gh_98() @@ -451,8 +451,8 @@ public function test_delegate_getter_gh_98() Venue::$use_custom_get_state_getter = true; $event = Event::first(); - $this->assert_equals('ny', $event->venue->state); - $this->assert_equals('ny', $event->state); + $this->assertEquals('ny', $event->venue->state); + $this->assertEquals('ny', $event->state); Venue::$use_custom_get_state_getter = false; } @@ -463,40 +463,40 @@ public function test_delegate_setter_gh_98() $event = Event::first(); $event->state = 'MEXICO'; - $this->assert_equals('MEXICO#',$event->venue->state); + $this->assertEquals('MEXICO#',$event->venue->state); Venue::$use_custom_set_state_setter = false; } public function test_table_name_with_underscores() { - $this->assert_not_null(AwesomePerson::first()); + $this->assertNotNull(AwesomePerson::first()); } public function test_model_should_default_as_new_record() { $author = new Author(); - $this->assert_true($author->is_new_record()); + $this->assertTrue($author->is_new_record()); } public function test_setter() { $author = new Author(); $author->password = 'plaintext'; - $this->assert_equals(md5('plaintext'),$author->encrypted_password); + $this->assertEquals(md5('plaintext'),$author->encrypted_password); } public function test_setter_with_same_name_as_an_attribute() { $author = new Author(); $author->name = 'bob'; - $this->assert_equals('BOB',$author->name); + $this->assertEquals('BOB',$author->name); } public function test_getter() { $book = Book::first(); - $this->assert_equals(strtoupper($book->name), $book->upper_name); + $this->assertEquals(strtoupper($book->name), $book->upper_name); } public function test_getter_with_same_name_as_an_attribute() @@ -504,7 +504,7 @@ public function test_getter_with_same_name_as_an_attribute() Book::$use_custom_get_name_getter = true; $book = new Book; $book->name = 'bob'; - $this->assert_equals('BOB', $book->name); + $this->assertEquals('BOB', $book->name); Book::$use_custom_get_name_getter = false; } @@ -517,7 +517,7 @@ public function test_setting_invalid_date_should_set_date_to_null() public function test_table_name() { - $this->assert_equals('authors',Author::table_name()); + $this->assertEquals('authors',Author::table_name()); } /** @@ -535,39 +535,39 @@ public function test_clear_cache_for_specific_class() ActiveRecord\Table::clear_cache('Book'); $book_table3 = ActiveRecord\Table::load('Book'); - $this->assert_true($book_table1 === $book_table2); - $this->assert_true($book_table1 !== $book_table3); + $this->assertTrue($book_table1 === $book_table2); + $this->assertTrue($book_table1 !== $book_table3); } public function test_flag_dirty() { $author = new Author(); $author->flag_dirty('some_date'); - $this->assert_has_keys('some_date', $author->dirty_attributes()); - $this->assert_true($author->attribute_is_dirty('some_date')); + $this->assertHasKeys('some_date', $author->dirty_attributes()); + $this->assertTrue($author->attribute_is_dirty('some_date')); $author->save(); - $this->assert_false($author->attribute_is_dirty('some_date')); + $this->assertFalse($author->attribute_is_dirty('some_date')); } public function test_flag_dirty_attribute_which_does_not_exit() { $author = new Author(); $author->flag_dirty('some_inexistant_property'); - $this->assert_null($author->dirty_attributes()); - $this->assert_false($author->attribute_is_dirty('some_inexistant_property')); + $this->assertNull($author->dirty_attributes()); + $this->assertFalse($author->attribute_is_dirty('some_inexistant_property')); } public function test_gh245_dirty_attribute_should_not_raise_php_notice_if_not_dirty() { $event = new Event(array('title' => "Fun")); - $this->assert_false($event->attribute_is_dirty('description')); - $this->assert_true($event->attribute_is_dirty('title')); + $this->assertFalse($event->attribute_is_dirty('description')); + $this->assertTrue($event->attribute_is_dirty('title')); } public function test_attribute_is_not_flagged_dirty_if_assigning_same_value() { $event = Event::find(1); $event->type = "Music"; - $this->assert_false($event->attribute_is_dirty('type')); + $this->assertFalse($event->attribute_is_dirty('type')); } public function test_changed_attributes() { @@ -575,17 +575,17 @@ public function test_changed_attributes() { $event->type = "Groovy Music"; $changed_attributes = $event->changed_attributes(); - $this->assert_true(is_array($changed_attributes)); - $this->assert_equals(1, count($changed_attributes)); - $this->assert_true(isset($changed_attributes['type'])); - $this->assert_equals("Music", $changed_attributes['type']); + $this->assertTrue(is_array($changed_attributes)); + $this->assertEquals(1, count($changed_attributes)); + $this->assertTrue(isset($changed_attributes['type'])); + $this->assertEquals("Music", $changed_attributes['type']); $event->type = "Funky Music"; $changed_attributes = $event->changed_attributes(); - $this->assert_true(is_array($changed_attributes)); - $this->assert_equals(1, count($changed_attributes)); - $this->assert_true(isset($changed_attributes['type'])); - $this->assert_equals("Music", $changed_attributes['type']); + $this->assertTrue(is_array($changed_attributes)); + $this->assertEquals(1, count($changed_attributes)); + $this->assertTrue(isset($changed_attributes['type'])); + $this->assertEquals("Music", $changed_attributes['type']); } public function test_changes() { @@ -593,44 +593,44 @@ public function test_changes() { $event->type = "Groovy Music"; $changes = $event->changes(); - $this->assert_true(is_array($changes)); - $this->assert_equals(1, count($changes)); - $this->assert_true(isset($changes['type'])); - $this->assert_true(is_array($changes['type'])); - $this->assert_equals("Music", $changes['type'][0]); - $this->assert_equals("Groovy Music", $changes['type'][1]); + $this->assertTrue(is_array($changes)); + $this->assertEquals(1, count($changes)); + $this->assertTrue(isset($changes['type'])); + $this->assertTrue(is_array($changes['type'])); + $this->assertEquals("Music", $changes['type'][0]); + $this->assertEquals("Groovy Music", $changes['type'][1]); $event->type = "Funky Music"; $changes = $event->changes(); - $this->assert_true(is_array($changes)); - $this->assert_equals(1, count($changes)); - $this->assert_true(isset($changes['type'])); - $this->assert_true(is_array($changes['type'])); - $this->assert_equals("Music", $changes['type'][0]); - $this->assert_equals("Funky Music", $changes['type'][1]); + $this->assertTrue(is_array($changes)); + $this->assertEquals(1, count($changes)); + $this->assertTrue(isset($changes['type'])); + $this->assertTrue(is_array($changes['type'])); + $this->assertEquals("Music", $changes['type'][0]); + $this->assertEquals("Funky Music", $changes['type'][1]); } public function test_attribute_was() { $event = Event::find(1); $event->type = "Funky Music"; - $this->assert_equals("Music", $event->attribute_was("type")); + $this->assertEquals("Music", $event->attribute_was("type")); $event->type = "Groovy Music"; - $this->assert_equals("Music", $event->attribute_was("type")); + $this->assertEquals("Music", $event->attribute_was("type")); } public function test_previous_changes() { $event = Event::find(1); $event->type = "Groovy Music"; $previous_changes = $event->previous_changes(); - $this->assert_true(empty($previous_changes)); + $this->assertTrue(empty($previous_changes)); $event->save(); $previous_changes = $event->previous_changes(); - $this->assert_true(is_array($previous_changes)); - $this->assert_equals(1, count($previous_changes)); - $this->assert_true(isset($previous_changes['type'])); - $this->assert_true(is_array($previous_changes['type'])); - $this->assert_equals("Music", $previous_changes['type'][0]); - $this->assert_equals("Groovy Music", $previous_changes['type'][1]); + $this->assertTrue(is_array($previous_changes)); + $this->assertEquals(1, count($previous_changes)); + $this->assertTrue(isset($previous_changes['type'])); + $this->assertTrue(is_array($previous_changes['type'])); + $this->assertEquals("Music", $previous_changes['type'][0]); + $this->assertEquals("Groovy Music", $previous_changes['type'][1]); } public function test_save_resets_changed_attributes() { @@ -638,7 +638,7 @@ public function test_save_resets_changed_attributes() { $event->type = "Groovy Music"; $event->save(); $changed_attributes = $event->changed_attributes(); - $this->assert_true(empty($changed_attributes)); + $this->assertTrue(empty($changed_attributes)); } public function test_changing_datetime_attribute_tracks_change() { @@ -646,26 +646,26 @@ public function test_changing_datetime_attribute_tracks_change() { $author->created_at = $original = new \DateTime("yesterday"); $author->created_at = $now = new \DateTime(); $changes = $author->changes(); - $this->assert_true(isset($changes['created_at'])); - $this->assert_datetime_equals($original, $changes['created_at'][0]); - $this->assert_datetime_equals($now, $changes['created_at'][1]); + $this->assertTrue(isset($changes['created_at'])); + $this->assertDateTimeEquals($original, $changes['created_at'][0]); + $this->assertDateTimeEquals($now, $changes['created_at'][1]); } public function test_changing_empty_attribute_value_tracks_change() { $event = new Event(); $event->description = "The most fun"; $changes = $event->changes(); - $this->assert_true(array_key_exists("description", $changes)); - $this->assert_equals("", $changes['description'][0]); - $this->assert_equals("The most fun", $changes['description'][1]); + $this->assertTrue(array_key_exists("description", $changes)); + $this->assertEquals("", $changes['description'][0]); + $this->assertEquals("The most fun", $changes['description'][1]); } public function test_assigning_php_datetime_gets_converted_to_date_class_with_defaults() { $author = new Author(); $author->created_at = $now = new \DateTime(); - $this->assert_is_a("ActiveRecord\\DateTime", $author->created_at); - $this->assert_datetime_equals($now,$author->created_at); + $this->assertIsA("ActiveRecord\\DateTime", $author->created_at); + $this->assertDateTimeEquals($now,$author->created_at); } public function test_assigning_php_datetime_gets_converted_to_date_class_with_custom_date_class() @@ -673,36 +673,36 @@ public function test_assigning_php_datetime_gets_converted_to_date_class_with_cu ActiveRecord\Config::instance()->set_date_class('\\DateTime'); // use PHP built-in DateTime $author = new Author(); $author->created_at = $now = new \DateTime(); - $this->assert_is_a("DateTime", $author->created_at); - $this->assert_datetime_equals($now,$author->created_at); + $this->assertIsA("DateTime", $author->created_at); + $this->assertDateTimeEquals($now,$author->created_at); } public function test_assigning_from_mass_assignment_php_datetime_gets_converted_to_ar_datetime() { $author = new Author(array('created_at' => new \DateTime())); - $this->assert_is_a("ActiveRecord\\DateTime",$author->created_at); + $this->assertIsA("ActiveRecord\\DateTime",$author->created_at); } public function test_get_real_attribute_name() { $venue = new Venue(); - $this->assert_equals('name', $venue->get_real_attribute_name('name')); - $this->assert_equals('name', $venue->get_real_attribute_name('marquee')); - $this->assert_equals(null, $venue->get_real_attribute_name('invalid_field')); + $this->assertEquals('name', $venue->get_real_attribute_name('name')); + $this->assertEquals('name', $venue->get_real_attribute_name('marquee')); + $this->assertEquals(null, $venue->get_real_attribute_name('invalid_field')); } public function test_id_setter_works_with_table_without_pk_named_attribute() { $author = new Author(array('id' => 123)); - $this->assert_equals(123,$author->author_id); + $this->assertEquals(123,$author->author_id); } public function test_query() { $row = Author::query('SELECT COUNT(*) AS n FROM authors',null)->fetch(); - $this->assert_true($row['n'] > 1); + $this->assertTrue($row['n'] > 1); $row = Author::query('SELECT COUNT(*) AS n FROM authors WHERE name=?',array('Tito'))->fetch(); - $this->assert_equals(array('n' => 1), $row); + $this->assertEquals(array('n' => 1), $row); } } diff --git a/test/ActiveRecordWriteTest.php b/test/ActiveRecordWriteTest.php index c0351413d..b846b4736 100644 --- a/test/ActiveRecordWriteTest.php +++ b/test/ActiveRecordWriteTest.php @@ -47,7 +47,7 @@ public function test_insert() { $author = new Author(array('name' => 'Blah Blah')); $author->save(); - $this->assert_not_null(Author::find($author->id)); + $this->assertNotNull(Author::find($author->id)); } /** @@ -65,30 +65,30 @@ public function test_insert_should_quote_keys() { $author = new Author(array('name' => 'Blah Blah')); $author->save(); - $this->assert_true(strpos($author->connection()->last_query,$author->connection()->quote_name('updated_at')) !== false); + $this->assertTrue(strpos($author->connection()->last_query,$author->connection()->quote_name('updated_at')) !== false); } public function test_save_auto_increment_id() { $venue = new Venue(array('name' => 'Bob')); $venue->save(); - $this->assert_true($venue->id > 0); + $this->assertTrue($venue->id > 0); } public function test_sequence_was_set() { if ($this->conn->supports_sequences()) - $this->assert_equals($this->conn->get_sequence_name('authors','author_id'),Author::table()->sequence); + $this->assertEquals($this->conn->get_sequence_name('authors','author_id'),Author::table()->sequence); else - $this->assert_null(Author::table()->sequence); + $this->assertNull(Author::table()->sequence); } public function test_sequence_was_explicitly_set() { if ($this->conn->supports_sequences()) - $this->assert_equals(AuthorExplicitSequence::$sequence,AuthorExplicitSequence::table()->sequence); + $this->assertEquals(AuthorExplicitSequence::$sequence,AuthorExplicitSequence::table()->sequence); else - $this->assert_null(Author::table()->sequence); + $this->assertNull(Author::table()->sequence); } public function test_delete() @@ -96,7 +96,7 @@ public function test_delete() $author = Author::find(1); $author->delete(); - $this->assert_false(Author::exists(1)); + $this->assertFalse(Author::exists(1)); } public function test_delete_by_find_all() @@ -107,7 +107,7 @@ public function test_delete_by_find_all() $model->delete(); $res = Book::all(); - $this->assert_equals(0,count($res)); + $this->assertEquals(0,count($res)); } public function test_update() @@ -117,8 +117,8 @@ public function test_update() $book->name = $new_name; $book->save(); - $this->assert_same($new_name, $book->name); - $this->assert_same($new_name, $book->name, Book::find(1)->name); + $this->assertSame($new_name, $book->name); + $this->assertSame($new_name, $book->name, Book::find(1)->name); } public function test_update_should_quote_keys() @@ -126,7 +126,7 @@ public function test_update_should_quote_keys() $book = Book::find(1); $book->name = 'new name'; $book->save(); - $this->assert_true(strpos($book->connection()->last_query,$book->connection()->quote_name('name')) !== false); + $this->assertTrue(strpos($book->connection()->last_query,$book->connection()->quote_name('name')) !== false); } public function test_update_attributes() @@ -136,8 +136,8 @@ public function test_update_attributes() $attrs = array('name' => $new_name); $book->update_attributes($attrs); - $this->assert_same($new_name, $book->name); - $this->assert_same($new_name, $book->name, Book::find(1)->name); + $this->assertSame($new_name, $book->name); + $this->assertSame($new_name, $book->name, Book::find(1)->name); } /** @@ -155,8 +155,8 @@ public function test_update_attribute() $new_name = 'some stupid self-help book'; $book->update_attribute('name', $new_name); - $this->assert_same($new_name, $book->name); - $this->assert_same($new_name, $book->name, Book::find(1)->name); + $this->assertSame($new_name, $book->name); + $this->assertSame($new_name, $book->name, Book::find(1)->name); } /** @@ -173,7 +173,7 @@ public function test_save_null_value() $book = Book::first(); $book->name = null; $book->save(); - $this->assert_same(null,Book::find($book->id)->name); + $this->assertSame(null,Book::find($book->id)->name); } public function test_save_blank_value() @@ -185,36 +185,36 @@ public function test_save_blank_value() $book = Book::find(1); $book->name = ''; $book->save(); - $this->assert_same('',Book::find(1)->name); + $this->assertSame('',Book::find(1)->name); } public function test_dirty_attributes() { $book = $this->make_new_book_and(false); - $this->assert_equals(array('name','special'),array_keys($book->dirty_attributes())); + $this->assertEquals(array('name','special'),array_keys($book->dirty_attributes())); } public function test_dirty_attributes_cleared_after_saving() { $book = $this->make_new_book_and(); - $this->assert_true(strpos($book->table()->last_sql,'name') !== false); - $this->assert_true(strpos($book->table()->last_sql,'special') !== false); - $this->assert_equals(null,$book->dirty_attributes()); + $this->assertTrue(strpos($book->table()->last_sql,'name') !== false); + $this->assertTrue(strpos($book->table()->last_sql,'special') !== false); + $this->assertEquals(null,$book->dirty_attributes()); } public function test_dirty_attributes_cleared_after_inserting() { $book = $this->make_new_book_and(); - $this->assert_equals(null,$book->dirty_attributes()); + $this->assertEquals(null,$book->dirty_attributes()); } public function test_no_dirty_attributes_but_still_insert_record() { $book = new Book; - $this->assert_equals(null,$book->dirty_attributes()); + $this->assertEquals(null,$book->dirty_attributes()); $book->save(); - $this->assert_equals(null,$book->dirty_attributes()); - $this->assert_not_null($book->id); + $this->assertEquals(null,$book->dirty_attributes()); + $this->assertNotNull($book->id); } public function test_dirty_attributes_cleared_after_updating() @@ -222,7 +222,7 @@ public function test_dirty_attributes_cleared_after_updating() $book = Book::first(); $book->name = 'rivers cuomo'; $book->save(); - $this->assert_equals(null,$book->dirty_attributes()); + $this->assertEquals(null,$book->dirty_attributes()); } public function test_dirty_attributes_after_reloading() @@ -230,24 +230,24 @@ public function test_dirty_attributes_after_reloading() $book = Book::first(); $book->name = 'rivers cuomo'; $book->reload(); - $this->assert_equals(null,$book->dirty_attributes()); + $this->assertEquals(null,$book->dirty_attributes()); } public function test_dirty_attributes_with_mass_assignment() { $book = Book::first(); $book->set_attributes(array('name' => 'rivers cuomo')); - $this->assert_equals(array('name'), array_keys($book->dirty_attributes())); + $this->assertEquals(array('name'), array_keys($book->dirty_attributes())); } public function test_timestamps_set_before_save() { $author = new Author; $author->save(); - $this->assert_not_null($author->created_at, $author->updated_at); + $this->assertNotNull($author->created_at, $author->updated_at); $author->reload(); - $this->assert_not_null($author->created_at, $author->updated_at); + $this->assertNotNull($author->created_at, $author->updated_at); } public function test_timestamps_updated_at_only_set_before_update() @@ -261,21 +261,21 @@ public function test_timestamps_updated_at_only_set_before_update() $author->name = 'test'; $author->save(); - $this->assert_not_null($author->updated_at); - $this->assert_same($created_at, $author->created_at); - $this->assert_not_equals($updated_at, $author->updated_at); + $this->assertNotNull($author->updated_at); + $this->assertSame($created_at, $author->created_at); + $this->assertNotEquals($updated_at, $author->updated_at); } public function test_create() { $author = Author::create(array('name' => 'Blah Blah')); - $this->assert_not_null(Author::find($author->id)); + $this->assertNotNull(Author::find($author->id)); } public function test_create_should_set_created_at() { $author = Author::create(array('name' => 'Blah Blah')); - $this->assert_not_null($author->created_at); + $this->assertNotNull($author->created_at); } /** @@ -302,7 +302,7 @@ public function test_delete_with_no_primary_key_defined() public function test_inserting_with_explicit_pk() { $author = Author::create(array('author_id' => 9999, 'name' => 'blah')); - $this->assert_equals(9999,$author->author_id); + $this->assertEquals(9999,$author->author_id); } /** @@ -319,16 +319,16 @@ public function test_modified_attributes_in_before_handlers_get_saved() $author = DirtyAuthor::first(); $author->encrypted_password = 'coco'; $author->save(); - $this->assert_equals('i saved',DirtyAuthor::find($author->id)->name); + $this->assertEquals('i saved',DirtyAuthor::find($author->id)->name); } public function test_is_dirty() { $author = Author::first(); - $this->assert_equals(false,$author->is_dirty()); + $this->assertEquals(false,$author->is_dirty()); $author->name = 'coco'; - $this->assert_equals(true,$author->is_dirty()); + $this->assertEquals(true,$author->is_dirty()); } public function test_set_date_flags_dirty() @@ -336,7 +336,7 @@ public function test_set_date_flags_dirty() $author = Author::create(array('some_date' => new DateTime())); $author = Author::find($author->id); $author->some_date->setDate(2010,1,1); - $this->assert_has_keys('some_date', $author->dirty_attributes()); + $this->assertHasKeys('some_date', $author->dirty_attributes()); } public function test_set_date_flags_dirty_with_php_datetime() @@ -344,48 +344,48 @@ public function test_set_date_flags_dirty_with_php_datetime() $author = Author::create(array('some_date' => new \DateTime())); $author = Author::find($author->id); $author->some_date->setDate(2010,1,1); - $this->assert_has_keys('some_date', $author->dirty_attributes()); + $this->assertHasKeys('some_date', $author->dirty_attributes()); } public function test_delete_all_with_conditions_as_string() { $num_affected = Author::delete_all(array('conditions' => 'parent_author_id = 2')); - $this->assert_equals(2, $num_affected); + $this->assertEquals(2, $num_affected); } public function test_delete_all_with_conditions_as_hash() { $num_affected = Author::delete_all(array('conditions' => array('parent_author_id' => 2))); - $this->assert_equals(2, $num_affected); + $this->assertEquals(2, $num_affected); } public function test_delete_all_with_conditions_as_array() { $num_affected = Author::delete_all(array('conditions' => array('parent_author_id = ?', 2))); - $this->assert_equals(2, $num_affected); + $this->assertEquals(2, $num_affected); } public function test_delete_all_with_limit_and_order() { if (!$this->conn->accepts_limit_and_order_for_update_and_delete()) - $this->mark_test_skipped('Only MySQL & Sqlite accept limit/order with UPDATE clause'); + $this->markTestSkipped('Only MySQL & Sqlite accept limit/order with UPDATE clause'); $num_affected = Author::delete_all(array('conditions' => array('parent_author_id = ?', 2), 'limit' => 1, 'order' => 'name asc')); - $this->assert_equals(1, $num_affected); - $this->assert_true(strpos(Author::table()->last_sql, 'ORDER BY name asc LIMIT 1') !== false); + $this->assertEquals(1, $num_affected); + $this->assertTrue(strpos(Author::table()->last_sql, 'ORDER BY name asc LIMIT 1') !== false); } public function test_update_all_with_set_as_string() { $num_affected = Author::update_all(array('set' => 'parent_author_id = 2')); - $this->assert_equals(2, $num_affected); - $this->assert_equals(4, Author::count_by_parent_author_id(2)); + $this->assertEquals(2, $num_affected); + $this->assertEquals(4, Author::count_by_parent_author_id(2)); } public function test_update_all_with_set_as_hash() { $num_affected = Author::update_all(array('set' => array('parent_author_id' => 2))); - $this->assert_equals(2, $num_affected); + $this->assertEquals(2, $num_affected); } /** @@ -393,36 +393,36 @@ public function test_update_all_with_set_as_hash() public function test_update_all_with_set_as_array() { $num_affected = Author::update_all(array('set' => array('parent_author_id = ?', 2))); - $this->assert_equals(2, $num_affected); + $this->assertEquals(2, $num_affected); } */ public function test_update_all_with_conditions_as_string() { $num_affected = Author::update_all(array('set' => 'parent_author_id = 2', 'conditions' => 'name = "Tito"')); - $this->assert_equals(1, $num_affected); + $this->assertEquals(1, $num_affected); } public function test_update_all_with_conditions_as_hash() { $num_affected = Author::update_all(array('set' => 'parent_author_id = 2', 'conditions' => array('name' => "Tito"))); - $this->assert_equals(1, $num_affected); + $this->assertEquals(1, $num_affected); } public function test_update_all_with_conditions_as_array() { $num_affected = Author::update_all(array('set' => 'parent_author_id = 2', 'conditions' => array('name = ?', "Tito"))); - $this->assert_equals(1, $num_affected); + $this->assertEquals(1, $num_affected); } public function test_update_all_with_limit_and_order() { if (!$this->conn->accepts_limit_and_order_for_update_and_delete()) - $this->mark_test_skipped('Only MySQL & Sqlite accept limit/order with UPDATE clause'); + $this->markTestSkipped('Only MySQL & Sqlite accept limit/order with UPDATE clause'); $num_affected = Author::update_all(array('set' => 'parent_author_id = 2', 'limit' => 1, 'order' => 'name asc')); - $this->assert_equals(1, $num_affected); - $this->assert_true(strpos(Author::table()->last_sql, 'ORDER BY name asc LIMIT 1') !== false); + $this->assertEquals(1, $num_affected); + $this->assertTrue(strpos(Author::table()->last_sql, 'ORDER BY name asc LIMIT 1') !== false); } public function test_update_native_datetime() @@ -430,7 +430,7 @@ public function test_update_native_datetime() $author = Author::create(array('name' => 'Blah Blah')); $native_datetime = new \DateTime('1983-12-05'); $author->some_date = $native_datetime; - $this->assert_false($native_datetime === $author->some_date); + $this->assertFalse($native_datetime === $author->some_date); } public function test_update_our_datetime() @@ -438,7 +438,7 @@ public function test_update_our_datetime() $author = Author::create(array('name' => 'Blah Blah')); $our_datetime = new DateTime('1983-12-05'); $author->some_date = $our_datetime; - $this->assert_true($our_datetime === $author->some_date); + $this->assertTrue($our_datetime === $author->some_date); } } diff --git a/test/CacheModelTest.php b/test/CacheModelTest.php index 8ae297244..fc3614c01 100644 --- a/test/CacheModelTest.php +++ b/test/CacheModelTest.php @@ -3,14 +3,14 @@ class CacheModelTest extends DatabaseTest { - public function set_up($connection_name=null) + public function setUp($connection_name=null) { if (!extension_loaded('memcache')) { $this->markTestSkipped('The memcache extension is not available'); return; } - parent::set_up($connection_name); + parent::setUp($connection_name); ActiveRecord\Config::instance()->set_cache('memcache://localhost'); } @@ -22,7 +22,7 @@ protected static function set_method_public($className, $methodName) return $method; } - public function tear_down() + public function tearDown() { Cache::flush(); Cache::initialize(null); @@ -30,12 +30,12 @@ public function tear_down() public function test_default_expire() { - $this->assert_equals(30,Author::table()->cache_model_expire); + $this->assertEquals(30,Author::table()->cache_model_expire); } public function test_explicit_expire() { - $this->assert_equals(2592000,Publisher::table()->cache_model_expire); + $this->assertEquals(2592000,Publisher::table()->cache_model_expire); } public function test_cache_key() @@ -43,7 +43,7 @@ public function test_cache_key() $method = $this->set_method_public('Author', 'cache_key'); $author = Author::first(); - $this->assert_equals("Author-1", $method->invokeArgs($author, array())); + $this->assertEquals("Author-1", $method->invokeArgs($author, array())); } public function test_model_cache_find_by_pk() diff --git a/test/CacheTest.php b/test/CacheTest.php index af5e5426c..7668b42c3 100644 --- a/test/CacheTest.php +++ b/test/CacheTest.php @@ -1,9 +1,9 @@ assert_not_null(Cache::$adapter); + $this->assertNotNull(Cache::$adapter); } public function test_initialize_with_null() { Cache::initialize(null); - $this->assert_null(Cache::$adapter); + $this->assertNull(Cache::$adapter); } public function test_get_returns_the_value() { - $this->assert_equals("abcd", $this->cache_get()); + $this->assertEquals("abcd", $this->cache_get()); } public function test_get_writes_to_the_cache() { $this->cache_get(); - $this->assert_equals("abcd", Cache::$adapter->read("1337")); + $this->assertEquals("abcd", Cache::$adapter->read("1337")); } public function test_get_does_not_execute_closure_on_cache_hit() @@ -54,13 +54,13 @@ public function test_get_does_not_execute_closure_on_cache_hit() public function test_cache_adapter_returns_false_on_cache_miss() { - $this->assert_same(false, Cache::$adapter->read("some-key")); + $this->assertSame(false, Cache::$adapter->read("some-key")); } public function test_get_works_without_caching_enabled() { Cache::$adapter = null; - $this->assert_equals("abcd", $this->cache_get()); + $this->assertEquals("abcd", $this->cache_get()); } public function test_cache_expire() @@ -69,14 +69,14 @@ public function test_cache_expire() $this->cache_get(); sleep(2); - $this->assert_same(false, Cache::$adapter->read("1337")); + $this->assertSame(false, Cache::$adapter->read("1337")); } public function test_namespace_is_set_properly() { Cache::$options['namespace'] = 'myapp'; $this->cache_get(); - $this->assert_same("abcd", Cache::$adapter->read("myapp::1337")); + $this->assertSame("abcd", Cache::$adapter->read("myapp::1337")); } /** diff --git a/test/CallbackTest.php b/test/CallbackTest.php index 9c1e46d29..e91b3126e 100644 --- a/test/CallbackTest.php +++ b/test/CallbackTest.php @@ -2,9 +2,9 @@ class CallBackTest extends DatabaseTest { - public function set_up($connection_name=null) + public function setUp($connection_name=null) { - parent::set_up($connection_name); + parent::setUp($connection_name); // ensure VenueCB model has been loaded VenueCB::find(1); @@ -12,21 +12,21 @@ public function set_up($connection_name=null) $this->callback = new ActiveRecord\CallBack('VenueCB'); } - public function assert_has_callback($callback_name, $method_name=null) + public function assertHasCallback($callback_name, $method_name=null) { if (!$method_name) $method_name = $callback_name; - $this->assert_true(in_array($method_name,$this->callback->get_callbacks($callback_name))); + $this->assertTrue(in_array($method_name,$this->callback->get_callbacks($callback_name))); } - public function assert_implicit_save($first_method, $second_method) + public function assertImplicitSave($first_method, $second_method) { $i_ran = array(); $this->callback->register($first_method,function($model) use (&$i_ran, $first_method) { $i_ran[] = $first_method; }); $this->callback->register($second_method,function($model) use (&$i_ran, $second_method) { $i_ran[] = $second_method; }); $this->callback->invoke(null,$second_method); - $this->assert_equals(array($first_method,$second_method),$i_ran); + $this->assertEquals(array($first_method,$second_method),$i_ran); } public function test_gh_266_calling_save_in_after_save_callback_uses_update_instead_of_insert() @@ -36,27 +36,27 @@ public function test_gh_266_calling_save_in_after_save_callback_uses_update_inst $venue->city = 'Awesome City'; $venue->save(); - $this->assert_true(VenueAfterCreate::exists(array('conditions'=> - array('name'=>'changed!')))); - $this->assert_false(VenueAfterCreate::exists(array('conditions'=> - array('name'=>'change me')))); + $this->assertTrue(VenueAfterCreate::exists(array('conditions'=> + array('name'=>'changed!')))); + $this->assertFalse(VenueAfterCreate::exists(array('conditions'=> + array('name'=>'change me')))); } public function test_generic_callback_was_auto_registered() { - $this->assert_has_callback('after_construct'); + $this->assertHasCallback('after_construct'); } public function test_register() { $this->callback->register('after_construct'); - $this->assert_has_callback('after_construct'); + $this->assertHasCallback('after_construct'); } public function test_register_non_generic() { $this->callback->register('after_construct','non_generic_after_construct'); - $this->assert_has_callback('after_construct','non_generic_after_construct'); + $this->assertHasCallback('after_construct','non_generic_after_construct'); } /** @@ -78,7 +78,7 @@ public function test_register_callback_with_undefined_method() public function test_register_with_string_definition() { $this->callback->register('after_construct','after_construct'); - $this->assert_has_callback('after_construct'); + $this->assertHasCallback('after_construct'); } public function test_register_with_closure() @@ -89,38 +89,38 @@ public function test_register_with_closure() public function test_register_with_null_definition() { $this->callback->register('after_construct',null); - $this->assert_has_callback('after_construct'); + $this->assertHasCallback('after_construct'); } public function test_register_with_no_definition() { $this->callback->register('after_construct'); - $this->assert_has_callback('after_construct'); + $this->assertHasCallback('after_construct'); } public function test_register_appends_to_registry() { $this->callback->register('after_construct'); $this->callback->register('after_construct','non_generic_after_construct'); - $this->assert_equals(array('after_construct','after_construct','non_generic_after_construct'),$this->callback->get_callbacks('after_construct')); + $this->assertEquals(array('after_construct','after_construct','non_generic_after_construct'),$this->callback->get_callbacks('after_construct')); } public function test_register_prepends_to_registry() { $this->callback->register('after_construct'); $this->callback->register('after_construct','non_generic_after_construct',array('prepend' => true)); - $this->assert_equals(array('non_generic_after_construct','after_construct','after_construct'),$this->callback->get_callbacks('after_construct')); + $this->assertEquals(array('non_generic_after_construct','after_construct','after_construct'),$this->callback->get_callbacks('after_construct')); } public function test_registers_via_static_array_definition() { - $this->assert_has_callback('after_destroy','after_destroy_one'); - $this->assert_has_callback('after_destroy','after_destroy_two'); + $this->assertHasCallback('after_destroy','after_destroy_one'); + $this->assertHasCallback('after_destroy','after_destroy_two'); } public function test_registers_via_static_string_definition() { - $this->assert_has_callback('before_destroy','before_destroy_using_string'); + $this->assertHasCallback('before_destroy','before_destroy_using_string'); } /** @@ -138,30 +138,30 @@ public function test_can_register_same_multiple_times() { $this->callback->register('after_construct'); $this->callback->register('after_construct'); - $this->assert_equals(array('after_construct','after_construct','after_construct'),$this->callback->get_callbacks('after_construct')); + $this->assertEquals(array('after_construct','after_construct','after_construct'),$this->callback->get_callbacks('after_construct')); } public function test_register_closure_callback() { $closure = function($model) {}; $this->callback->register('after_save',$closure); - $this->assert_equals(array($closure),$this->callback->get_callbacks('after_save')); + $this->assertEquals(array($closure),$this->callback->get_callbacks('after_save')); } public function test_get_callbacks_returns_array() { $this->callback->register('after_construct'); - $this->assert_true(is_array($this->callback->get_callbacks('after_construct'))); + $this->assertTrue(is_array($this->callback->get_callbacks('after_construct'))); } public function test_get_callbacks_returns_null() { - $this->assert_null($this->callback->get_callbacks('this_callback_name_should_never_exist')); + $this->assertNull($this->callback->get_callbacks('this_callback_name_should_never_exist')); } public function test_invoke_runs_all_callbacks() { - $mock = $this->get_mock('VenueCB',array('after_destroy_one','after_destroy_two')); + $mock = $this->getMock('VenueCB',array('after_destroy_one','after_destroy_two')); $mock->expects($this->once())->method('after_destroy_one'); $mock->expects($this->once())->method('after_destroy_two'); $this->callback->invoke($mock,'after_destroy'); @@ -172,15 +172,15 @@ public function test_invoke_closure() $i_ran = false; $this->callback->register('after_validation',function($model) use (&$i_ran) { $i_ran = true; }); $this->callback->invoke(null,'after_validation'); - $this->assert_true($i_ran); + $this->assertTrue($i_ran); } public function test_invoke_implicitly_calls_save_first() { - $this->assert_implicit_save('before_save','before_create'); - $this->assert_implicit_save('before_save','before_update'); - $this->assert_implicit_save('after_save','after_create'); - $this->assert_implicit_save('after_save','after_update'); + $this->assertImplicitSave('before_save','before_create'); + $this->assertImplicitSave('before_save','before_update'); + $this->assertImplicitSave('after_save','after_create'); + $this->assertImplicitSave('after_save','after_update'); } /** @@ -188,26 +188,26 @@ public function test_invoke_implicitly_calls_save_first() */ public function test_invoke_unregistered_callback() { - $mock = $this->get_mock('VenueCB', array('columns')); + $mock = $this->getMock('VenueCB', array('columns')); $this->callback->invoke($mock,'before_validation_on_create'); } public function test_before_callbacks_pass_on_false_return_callback_returned_false() { $this->callback->register('before_validation',function($model) { return false; }); - $this->assert_false($this->callback->invoke(null,'before_validation')); + $this->assertFalse($this->callback->invoke(null,'before_validation')); } public function test_before_callbacks_does_not_pass_on_false_for_after_callbacks() { $this->callback->register('after_validation',function($model) { return false; }); - $this->assert_true($this->callback->invoke(null,'after_validation')); + $this->assertTrue($this->callback->invoke(null,'after_validation')); } public function test_gh_28_after_create_should_be_invoked_after_auto_incrementing_pk_is_set() { $that = $this; - VenueCB::$after_create = function($model) use ($that) { $that->assert_not_null($model->id); }; + VenueCB::$after_create = function($model) use ($that) { $that->assertNotNull($model->id); }; ActiveRecord\Table::clear_cache('VenueCB'); $venue = VenueCB::find(1); $venue = new VenueCB($venue->attributes()); @@ -232,9 +232,9 @@ public function test_before_create_returned_false_halts_execution() $v->id = null; VenueCB::create($v->attributes()); - $this->assert_true($i_should_have_ran); - $this->assert_false($i_ran); - $this->assert_true(strpos(ActiveRecord\Table::load('VenueCB')->last_sql, 'INSERT') === false); + $this->assertTrue($i_should_have_ran); + $this->assertFalse($i_ran); + $this->assertTrue(strpos(ActiveRecord\Table::load('VenueCB')->last_sql, 'INSERT') === false); } public function test_before_save_returned_false_halts_execution() @@ -253,10 +253,10 @@ public function test_before_save_returned_false_halts_execution() $v->name .= 'test'; $ret = $v->save(); - $this->assert_true($i_should_have_ran); - $this->assert_false($i_ran); - $this->assert_false($ret); - $this->assert_true(strpos(ActiveRecord\Table::load('VenueCB')->last_sql, 'UPDATE') === false); + $this->assertTrue($i_should_have_ran); + $this->assertFalse($i_ran); + $this->assertFalse($ret); + $this->assertTrue(strpos(ActiveRecord\Table::load('VenueCB')->last_sql, 'UPDATE') === false); } public function test_before_destroy_returned_false_halts_execution() @@ -272,9 +272,9 @@ public function test_before_destroy_returned_false_halts_execution() $v = VenueCB::find(1); $ret = $v->delete(); - $this->assert_false($i_ran); - $this->assert_false($ret); - $this->assert_true(strpos(ActiveRecord\Table::load('VenueCB')->last_sql, 'DELETE') === false); + $this->assertFalse($i_ran); + $this->assertFalse($ret); + $this->assertTrue(strpos(ActiveRecord\Table::load('VenueCB')->last_sql, 'DELETE') === false); } public function test_before_validation_returned_false_halts_execution() @@ -287,7 +287,7 @@ public function test_before_validation_returned_false_halts_execution() $v->name .= 'test'; $ret = $v->save(); - $this->assert_false($ret); - $this->assert_true(strpos(ActiveRecord\Table::load('VenueCB')->last_sql, 'UPDATE') === false); + $this->assertFalse($ret); + $this->assertTrue(strpos(ActiveRecord\Table::load('VenueCB')->last_sql, 'UPDATE') === false); } } diff --git a/test/ColumnTest.php b/test/ColumnTest.php index c36dceeca..72fb46c81 100644 --- a/test/ColumnTest.php +++ b/test/ColumnTest.php @@ -4,100 +4,100 @@ use ActiveRecord\DateTime; use ActiveRecord\DatabaseException; -class ColumnTest extends SnakeCase_PHPUnit_Framework_TestCase +class ColumnTest extends TestCase { - public function set_up() + public function setUp() { $this->column = new Column(); try { $this->conn = ActiveRecord\ConnectionManager::get_connection(ActiveRecord\Config::instance()->get_default_connection()); } catch (DatabaseException $e) { - $this->mark_test_skipped('failed to connect using default connection. '.$e->getMessage()); + $this->markTestSkipped('failed to connect using default connection. '.$e->getMessage()); } } - public function assert_mapped_type($type, $raw_type) + public function assertMappedType($type, $raw_type) { $this->column->raw_type = $raw_type; - $this->assert_equals($type,$this->column->map_raw_type()); + $this->assertEquals($type,$this->column->map_raw_type()); } - public function assert_cast($type, $casted_value, $original_value) + public function assertCast($type, $casted_value, $original_value) { $this->column->type = $type; $value = $this->column->cast($original_value,$this->conn); if ($original_value != null && ($type == Column::DATETIME || $type == Column::DATE)) - $this->assert_true($value instanceof DateTime); + $this->assertTrue($value instanceof DateTime); else - $this->assert_same($casted_value,$value); + $this->assertSame($casted_value,$value); } public function test_map_raw_type_dates() { - $this->assert_mapped_type(Column::DATETIME,'datetime'); - $this->assert_mapped_type(Column::DATE,'date'); + $this->assertMappedType(Column::DATETIME,'datetime'); + $this->assertMappedType(Column::DATE,'date'); } public function test_map_raw_type_integers() { - $this->assert_mapped_type(Column::INTEGER,'integer'); - $this->assert_mapped_type(Column::INTEGER,'int'); - $this->assert_mapped_type(Column::INTEGER,'tinyint'); - $this->assert_mapped_type(Column::INTEGER,'smallint'); - $this->assert_mapped_type(Column::INTEGER,'mediumint'); - $this->assert_mapped_type(Column::INTEGER,'bigint'); + $this->assertMappedType(Column::INTEGER,'integer'); + $this->assertMappedType(Column::INTEGER,'int'); + $this->assertMappedType(Column::INTEGER,'tinyint'); + $this->assertMappedType(Column::INTEGER,'smallint'); + $this->assertMappedType(Column::INTEGER,'mediumint'); + $this->assertMappedType(Column::INTEGER,'bigint'); } public function test_map_raw_type_decimals() { - $this->assert_mapped_type(Column::DECIMAL,'float'); - $this->assert_mapped_type(Column::DECIMAL,'double'); - $this->assert_mapped_type(Column::DECIMAL,'numeric'); - $this->assert_mapped_type(Column::DECIMAL,'dec'); + $this->assertMappedType(Column::DECIMAL,'float'); + $this->assertMappedType(Column::DECIMAL,'double'); + $this->assertMappedType(Column::DECIMAL,'numeric'); + $this->assertMappedType(Column::DECIMAL,'dec'); } public function test_map_raw_type_strings() { - $this->assert_mapped_type(Column::STRING,'string'); - $this->assert_mapped_type(Column::STRING,'varchar'); - $this->assert_mapped_type(Column::STRING,'text'); + $this->assertMappedType(Column::STRING,'string'); + $this->assertMappedType(Column::STRING,'varchar'); + $this->assertMappedType(Column::STRING,'text'); } public function test_map_raw_type_default_to_string() { - $this->assert_mapped_type(Column::STRING,'bajdslfjasklfjlksfd'); + $this->assertMappedType(Column::STRING,'bajdslfjasklfjlksfd'); } public function test_map_raw_type_changes_integer_to_int() { $this->column->raw_type = 'integer'; $this->column->map_raw_type(); - $this->assert_equals('int',$this->column->raw_type); + $this->assertEquals('int',$this->column->raw_type); } public function test_cast() { $datetime = new DateTime('2001-01-01'); - $this->assert_cast(Column::INTEGER,1,'1'); - $this->assert_cast(Column::INTEGER,1,'1.5'); - $this->assert_cast(Column::DECIMAL,1.5,'1.5'); - $this->assert_cast(Column::DATETIME,$datetime,'2001-01-01'); - $this->assert_cast(Column::DATE,$datetime,'2001-01-01'); - $this->assert_cast(Column::DATE,$datetime,$datetime); - $this->assert_cast(Column::STRING,'bubble tea','bubble tea'); - $this->assert_cast(Column::INTEGER,4294967295,'4294967295'); - $this->assert_cast(Column::INTEGER,'18446744073709551615','18446744073709551615'); + $this->assertCast(Column::INTEGER,1,'1'); + $this->assertCast(Column::INTEGER,1,'1.5'); + $this->assertCast(Column::DECIMAL,1.5,'1.5'); + $this->assertCast(Column::DATETIME,$datetime,'2001-01-01'); + $this->assertCast(Column::DATE,$datetime,'2001-01-01'); + $this->assertCast(Column::DATE,$datetime,$datetime); + $this->assertCast(Column::STRING,'bubble tea','bubble tea'); + $this->assertCast(Column::INTEGER,4294967295,'4294967295'); + $this->assertCast(Column::INTEGER,'18446744073709551615','18446744073709551615'); // 32 bit if (PHP_INT_SIZE === 4) - $this->assert_cast(Column::INTEGER,'2147483648',(((float) PHP_INT_MAX) + 1)); + $this->assertCast(Column::INTEGER,'2147483648',(((float) PHP_INT_MAX) + 1)); // 64 bit elseif (PHP_INT_SIZE === 8) - $this->assert_cast(Column::INTEGER,'9223372036854775808',(((float) PHP_INT_MAX) + 1)); + $this->assertCast(Column::INTEGER,'9223372036854775808',(((float) PHP_INT_MAX) + 1)); - $this->assert_cast(Column::BOOLEAN,$this->conn->boolean_to_string(true),true); - $this->assert_cast(Column::BOOLEAN,$this->conn->boolean_to_string(false),false); + $this->assertCast(Column::BOOLEAN,$this->conn->boolean_to_string(true),true); + $this->assertCast(Column::BOOLEAN,$this->conn->boolean_to_string(false),false); } public function test_cast_leave_null_alone() @@ -111,7 +111,7 @@ public function test_cast_leave_null_alone() Column::BOOLEAN); foreach ($types as $type) { - $this->assert_cast($type,null,null); + $this->assertCast($type,null,null); } } @@ -119,16 +119,16 @@ public function test_empty_and_null_date_strings_should_return_null() { $column = new Column(); $column->type = Column::DATE; - $this->assert_equals(null,$column->cast(null,$this->conn)); - $this->assert_equals(null,$column->cast('',$this->conn)); + $this->assertEquals(null,$column->cast(null,$this->conn)); + $this->assertEquals(null,$column->cast('',$this->conn)); } public function test_empty_and_null_datetime_strings_should_return_null() { $column = new Column(); $column->type = Column::DATETIME; - $this->assert_equals(null,$column->cast(null,$this->conn)); - $this->assert_equals(null,$column->cast('',$this->conn)); + $this->assertEquals(null,$column->cast(null,$this->conn)); + $this->assertEquals(null,$column->cast('',$this->conn)); } public function test_native_date_time_attribute_copies_exact_tz() @@ -140,9 +140,9 @@ public function test_native_date_time_attribute_copies_exact_tz() $dt2 = $column->cast($dt, $this->conn); - $this->assert_equals($dt->getTimestamp(), $dt2->getTimestamp()); - $this->assert_equals($dt->getTimeZone(), $dt2->getTimeZone()); - $this->assert_equals($dt->getTimeZone()->getName(), $dt2->getTimeZone()->getName()); + $this->assertEquals($dt->getTimestamp(), $dt2->getTimestamp()); + $this->assertEquals($dt->getTimeZone(), $dt2->getTimeZone()); + $this->assertEquals($dt->getTimeZone()->getName(), $dt2->getTimeZone()->getName()); } public function test_ar_date_time_attribute_copies_exact_tz() @@ -154,8 +154,8 @@ public function test_ar_date_time_attribute_copies_exact_tz() $dt2 = $column->cast($dt, $this->conn); - $this->assert_equals($dt->getTimestamp(), $dt2->getTimestamp()); - $this->assert_equals($dt->getTimeZone(), $dt2->getTimeZone()); - $this->assert_equals($dt->getTimeZone()->getName(), $dt2->getTimeZone()->getName()); + $this->assertEquals($dt->getTimestamp(), $dt2->getTimestamp()); + $this->assertEquals($dt->getTimeZone(), $dt2->getTimeZone()); + $this->assertEquals($dt->getTimeZone()->getName(), $dt2->getTimeZone()->getName()); } } diff --git a/test/ConfigTest.php b/test/ConfigTest.php index f15510a27..3af2d9056 100644 --- a/test/ConfigTest.php +++ b/test/ConfigTest.php @@ -19,9 +19,9 @@ public function format($format=null) {} public static function createFromFormat($format, $time) {} } -class ConfigTest extends SnakeCase_PHPUnit_Framework_TestCase +class ConfigTest extends TestCase { - public function set_up() + public function setUp() { $this->config = new Config(); $this->connections = array( @@ -46,51 +46,51 @@ public function test_set_connections_must_be_array() public function test_get_connections() { $connections = $this->config->get_connections(); - $this->assert_instance_of('ActiveRecord\ConnectionInfo', $connections['development']); - $this->assert_equals('development', $connections['development']->database); + $this->assertInstanceOf('ActiveRecord\ConnectionInfo', $connections['development']); + $this->assertEquals('development', $connections['development']->database); } public function test_get_connection_info() { $connection = $this->config->get_connection_info('development'); - $this->assert_instance_of('ActiveRecord\ConnectionInfo', $connection); - $this->assert_equals('development', $connection->database); + $this->assertInstanceOf('ActiveRecord\ConnectionInfo', $connection); + $this->assertEquals('development', $connection->database); } public function test_get_invalid_connection() { - $this->assert_null($this->config->get_connection_info('whiskey tango foxtrot')); + $this->assertNull($this->config->get_connection_info('whiskey tango foxtrot')); } public function test_get_default_connection_and_connection() { $this->config->set_default_connection('test'); - $this->assert_equals('test', $this->config->get_default_connection()); - $this->assert_equals('test', $this->config->get_default_connection_info()->database); + $this->assertEquals('test', $this->config->get_default_connection()); + $this->assertEquals('test', $this->config->get_default_connection_info()->database); } public function test_get_default_connection_and_connection_info_defaults_to_development() { - $this->assert_equals('development', $this->config->get_default_connection()); - $this->assert_equals('development', $this->config->get_default_connection_info()->database); + $this->assertEquals('development', $this->config->get_default_connection()); + $this->assertEquals('development', $this->config->get_default_connection_info()->database); } public function test_get_default_connection_info_when_connection_name_is_not_valid() { $this->config->set_default_connection('little mac'); - $this->assert_null($this->config->get_default_connection_info()); + $this->assertNull($this->config->get_default_connection_info()); } public function test_default_connection_is_set_when_only_one_connection_is_present() { $this->config->set_connections(array('development' => $this->connections['development'])); - $this->assert_equals('development',$this->config->get_default_connection()); + $this->assertEquals('development',$this->config->get_default_connection()); } public function test_set_connections_with_default() { $this->config->set_connections($this->connections,'test'); - $this->assert_equals('test',$this->config->get_default_connection()); + $this->assertEquals('test',$this->config->get_default_connection()); } /** @@ -103,7 +103,7 @@ public function test_set_model_directories_must_be_array() public function test_get_date_class_with_default() { - $this->assert_equals('ActiveRecord\\DateTime', $this->config->get_date_class()); + $this->assertEquals('ActiveRecord\\DateTime', $this->config->get_date_class()); } /** @@ -144,7 +144,7 @@ public function test_get_model_directory_returns_first_model_directory(){ realpath(__DIR__ . '/models'), realpath(__DIR__ . '/backup-models'), )); - $this->assert_equals(realpath(__DIR__ . '/models'), $this->config->get_model_directory()); + $this->assertEquals(realpath(__DIR__ . '/models'), $this->config->get_model_directory()); ActiveRecord\Config::instance()->set_model_directory($home); } @@ -168,7 +168,7 @@ public function test_set_date_class_when_class_doesnt_have_createfromformat() public function test_set_date_class_with_valid_class() { $this->config->set_date_class('TestDateTime'); - $this->assert_equals('TestDateTime', $this->config->get_date_class()); + $this->assertEquals('TestDateTime', $this->config->get_date_class()); } public function test_initialize_closure() @@ -177,8 +177,8 @@ public function test_initialize_closure() Config::initialize(function($cfg) use ($test) { - $test->assert_not_null($cfg); - $test->assert_equals('ActiveRecord\Config',get_class($cfg)); + $test->assertNotNull($cfg); + $test->assertEquals('ActiveRecord\Config',get_class($cfg)); }); } @@ -188,7 +188,7 @@ public function test_logger_object_must_implement_log_method() $this->config->set_logger(new TestLogger); $this->fail(); } catch (ConfigException $e) { - $this->assert_equals($e->getMessage(), "Logger object must implement a public log method"); + $this->assertEquals($e->getMessage(), "Logger object must implement a public log method"); } } } diff --git a/test/ConnectionInfoTest.php b/test/ConnectionInfoTest.php index cea868509..15a935a12 100644 --- a/test/ConnectionInfoTest.php +++ b/test/ConnectionInfoTest.php @@ -2,7 +2,7 @@ use ActiveRecord\ConnectionInfo; -class ConnectionInfoTest extends SnakeCase_PHPUnit_Framework_TestCase +class ConnectionInfoTest extends TestCase { /** * @expectedException ActiveRecord\DatabaseException @@ -15,18 +15,18 @@ public function test_connection_info_from_should_throw_exception_when_no_host() public function test_connection_info() { $info = ConnectionInfo::from_connection_url('mysql://user:pass@127.0.0.1:3306/dbname'); - $this->assert_equals('mysql', $info->adapter); - $this->assert_equals('user', $info->username); - $this->assert_equals('pass', $info->password); - $this->assert_equals('127.0.0.1', $info->host); - $this->assert_equals(3306, $info->port); - $this->assert_equals('dbname', $info->database); + $this->assertEquals('mysql', $info->adapter); + $this->assertEquals('user', $info->username); + $this->assertEquals('pass', $info->password); + $this->assertEquals('127.0.0.1', $info->host); + $this->assertEquals(3306, $info->port); + $this->assertEquals('dbname', $info->database); } public function test_gh_103_sqlite_connection_string_relative() { $info = ConnectionInfo::from_connection_url('sqlite://../some/path/to/file.db'); - $this->assert_equals('../some/path/to/file.db', $info->host); + $this->assertEquals('../some/path/to/file.db', $info->host); } /** @@ -40,39 +40,39 @@ public function test_gh_103_sqlite_connection_string_absolute() public function test_gh_103_sqlite_connection_string_unix() { $info = ConnectionInfo::from_connection_url('sqlite://unix(/some/path/to/file.db)'); - $this->assert_equals('/some/path/to/file.db', $info->host); + $this->assertEquals('/some/path/to/file.db', $info->host); $info = ConnectionInfo::from_connection_url('sqlite://unix(/some/path/to/file.db)/'); - $this->assert_equals('/some/path/to/file.db', $info->host); + $this->assertEquals('/some/path/to/file.db', $info->host); $info = ConnectionInfo::from_connection_url('sqlite://unix(/some/path/to/file.db)/dummy'); - $this->assert_equals('/some/path/to/file.db', $info->host); + $this->assertEquals('/some/path/to/file.db', $info->host); } public function test_gh_103_sqlite_connection_string_windows() { $info = ConnectionInfo::from_connection_url('sqlite://windows(c%3A/some/path/to/file.db)'); - $this->assert_equals('c:/some/path/to/file.db', $info->host); + $this->assertEquals('c:/some/path/to/file.db', $info->host); } public function test_parse_connection_url_with_unix_sockets() { $info = ConnectionInfo::from_connection_url('mysql://user:password@unix(/tmp/mysql.sock)/database'); - $this->assert_equals('/tmp/mysql.sock', $info->host); - $this->assert_equals('database', $info->database); + $this->assertEquals('/tmp/mysql.sock', $info->host); + $this->assertEquals('database', $info->database); } public function test_parse_connection_url_with_decode_option() { $info = ConnectionInfo::from_connection_url('mysql://h%20az:h%40i@127.0.0.1/test?decode=true'); - $this->assert_equals('h az', $info->username); - $this->assert_equals('h@i', $info->password); + $this->assertEquals('h az', $info->username); + $this->assertEquals('h@i', $info->password); } public function test_encoding() { $info = ConnectionInfo::from_connection_url('mysql://test:test@127.0.0.1/test?charset=utf8'); - $this->assert_equals('utf8', $info->charset); + $this->assertEquals('utf8', $info->charset); } public function test_connection_info_from_array(){ @@ -84,12 +84,12 @@ public function test_connection_info_from_array(){ 'username' => 'user', 'password' => 'pass' )); - $this->assert_equals('mysql', $info->adapter); - $this->assert_equals('user', $info->username); - $this->assert_equals('pass', $info->password); - $this->assert_equals('127.0.0.1', $info->host); - $this->assert_equals(3306, $info->port); - $this->assert_equals('dbname', $info->database); + $this->assertEquals('mysql', $info->adapter); + $this->assertEquals('user', $info->username); + $this->assertEquals('pass', $info->password); + $this->assertEquals('127.0.0.1', $info->host); + $this->assertEquals(3306, $info->port); + $this->assertEquals('dbname', $info->database); } } diff --git a/test/ConnectionManagerTest.php b/test/ConnectionManagerTest.php index 6e1e02580..f6d32b3f6 100644 --- a/test/ConnectionManagerTest.php +++ b/test/ConnectionManagerTest.php @@ -7,26 +7,26 @@ class ConnectionManagerTest extends DatabaseTest { public function test_get_connection_with_null_connection() { - $this->assert_not_null(ConnectionManager::get_connection(null)); - $this->assert_not_null(ConnectionManager::get_connection()); + $this->assertNotNull(ConnectionManager::get_connection(null)); + $this->assertNotNull(ConnectionManager::get_connection()); } public function test_get_connection() { - $this->assert_not_null(ConnectionManager::get_connection('mysql')); + $this->assertNotNull(ConnectionManager::get_connection('mysql')); } public function test_get_connection_uses_existing_object() { $connection = ConnectionManager::get_connection('mysql'); - $this->assert_same($connection, ConnectionManager::get_connection('mysql')); + $this->assertSame($connection, ConnectionManager::get_connection('mysql')); } public function test_get_connection_with_default() { $default = ActiveRecord\Config::instance()->get_default_connection('mysql'); $connection = ConnectionManager::get_connection(); - $this->assert_same(ConnectionManager::get_connection($default), $connection); + $this->assertSame(ConnectionManager::get_connection($default), $connection); } public function test_gh_91_get_connection_with_null_connection_is_always_default() @@ -36,22 +36,22 @@ public function test_gh_91_get_connection_with_null_connection_is_always_default $conn_three = ConnectionManager::get_connection('mysql'); $conn_four = ConnectionManager::get_connection(); - $this->assert_same($conn_one, $conn_three); - $this->assert_same($conn_two, $conn_three); - $this->assert_same($conn_four, $conn_three); + $this->assertSame($conn_one, $conn_three); + $this->assertSame($conn_two, $conn_three); + $this->assertSame($conn_four, $conn_three); } public function test_drop_connection() { $connection = ConnectionManager::get_connection('mysql'); ConnectionManager::drop_connection('mysql'); - $this->assert_not_same($connection, ConnectionManager::get_connection('mysql')); + $this->assertNotSame($connection, ConnectionManager::get_connection('mysql')); } public function test_drop_connection_with_default() { $connection = ConnectionManager::get_connection(); ConnectionManager::drop_connection(); - $this->assert_not_same($connection, ConnectionManager::get_connection()); + $this->assertNotSame($connection, ConnectionManager::get_connection()); } } diff --git a/test/DateFormatTest.php b/test/DateFormatTest.php index b18faffd7..780015ffa 100644 --- a/test/DateFormatTest.php +++ b/test/DateFormatTest.php @@ -11,7 +11,7 @@ public function test_datefield_gets_converted_to_ar_datetime() $author->save(); $author = Author::first(); - $this->assert_is_a("ActiveRecord\\DateTime",$author->some_date); + $this->assertIsA("ActiveRecord\\DateTime",$author->some_date); } } diff --git a/test/DateTimeTest.php b/test/DateTimeTest.php index 14839da16..af6738858 100644 --- a/test/DateTimeTest.php +++ b/test/DateTimeTest.php @@ -2,15 +2,15 @@ use ActiveRecord\DatabaseException; use ActiveRecord\DateTime as DateTime; -class DateTimeTest extends SnakeCase_PHPUnit_Framework_TestCase +class DateTimeTest extends TestCase { - public function set_up() + public function setUp() { $this->date = new DateTime(); $this->original_format = DateTime::$DEFAULT_FORMAT; } - public function tear_down() + public function tearDown() { DateTime::$DEFAULT_FORMAT = $this->original_format; } @@ -20,13 +20,13 @@ private function get_model() try { $model = new Author(); } catch (DatabaseException $e) { - $this->mark_test_skipped('failed to connect. '.$e->getMessage()); + $this->markTestSkipped('failed to connect. '.$e->getMessage()); } return $model; } - private function assert_dirtifies($method /*, method params, ...*/) + private function assertDirtifies($method /*, method params, ...*/) { $model = $this->get_model(); $datetime = new DateTime(); @@ -36,21 +36,21 @@ private function assert_dirtifies($method /*, method params, ...*/) array_shift($args); call_user_func_array(array($datetime,$method),$args); - $this->assert_has_keys('some_date', $model->dirty_attributes()); + $this->assertHasKeys('some_date', $model->dirty_attributes()); } public function test_should_flag_the_attribute_dirty() { $interval = new DateInterval('PT1S'); $timezone = new DateTimeZone('America/New_York'); - $this->assert_dirtifies('setDate',2001,1,1); - $this->assert_dirtifies('setISODate',2001,1); - $this->assert_dirtifies('setTime',1,1); - $this->assert_dirtifies('setTimestamp',1); - $this->assert_dirtifies('setTimezone',$timezone); - $this->assert_dirtifies('modify','+1 day'); - $this->assert_dirtifies('add',$interval); - $this->assert_dirtifies('sub',$interval); + $this->assertDirtifies('setDate',2001,1,1); + $this->assertDirtifies('setISODate',2001,1); + $this->assertDirtifies('setTime',1,1); + $this->assertDirtifies('setTimestamp',1); + $this->assertDirtifies('setTimezone',$timezone); + $this->assertDirtifies('modify','+1 day'); + $this->assertDirtifies('add',$interval); + $this->assertDirtifies('sub',$interval); } public function test_set_iso_date() @@ -61,7 +61,7 @@ public function test_set_iso_date() $b = new DateTime(); $b->setISODate(2001,1); - $this->assert_datetime_equals($a,$b); + $this->assertDateTimeEquals($a,$b); } public function test_set_time() @@ -72,7 +72,7 @@ public function test_set_time() $b = new DateTime(); $b->setTime(1,1); - $this->assert_datetime_equals($a,$b); + $this->assertDateTimeEquals($a,$b); } public function test_set_time_microseconds() @@ -83,81 +83,81 @@ public function test_set_time_microseconds() $b = new DateTime(); $b->setTime(1, 1, 1, 0); - $this->assert_datetime_equals($a,$b); + $this->assertDateTimeEquals($a,$b); } public function test_get_format_with_friendly() { - $this->assert_equals('Y-m-d H:i:s', DateTime::get_format('db')); + $this->assertEquals('Y-m-d H:i:s', DateTime::get_format('db')); } public function test_get_format_with_format() { - $this->assert_equals('Y-m-d', DateTime::get_format('Y-m-d')); + $this->assertEquals('Y-m-d', DateTime::get_format('Y-m-d')); } public function test_get_format_with_null() { - $this->assert_equals(\DateTime::RFC2822, DateTime::get_format()); + $this->assertEquals(\DateTime::RFC2822, DateTime::get_format()); } public function test_format() { - $this->assert_true(is_string($this->date->format())); - $this->assert_true(is_string($this->date->format('Y-m-d'))); + $this->assertTrue(is_string($this->date->format())); + $this->assertTrue(is_string($this->date->format('Y-m-d'))); } public function test_format_by_friendly_name() { $d = date(DateTime::get_format('db')); - $this->assert_equals($d, $this->date->format('db')); + $this->assertEquals($d, $this->date->format('db')); } public function test_format_by_custom_format() { $format = 'Y/m/d'; - $this->assert_equals(date($format), $this->date->format($format)); + $this->assertEquals(date($format), $this->date->format($format)); } public function test_format_uses_default() { $d = date(DateTime::$FORMATS[DateTime::$DEFAULT_FORMAT]); - $this->assert_equals($d, $this->date->format()); + $this->assertEquals($d, $this->date->format()); } public function test_all_formats() { foreach (DateTime::$FORMATS as $name => $format) - $this->assert_equals(date($format), $this->date->format($name)); + $this->assertEquals(date($format), $this->date->format($name)); } public function test_change_default_format_to_format_string() { DateTime::$DEFAULT_FORMAT = 'H:i:s'; - $this->assert_equals(date(DateTime::$DEFAULT_FORMAT), $this->date->format()); + $this->assertEquals(date(DateTime::$DEFAULT_FORMAT), $this->date->format()); } public function test_change_default_format_to_friently() { DateTime::$DEFAULT_FORMAT = 'short'; - $this->assert_equals(date(DateTime::$FORMATS['short']), $this->date->format()); + $this->assertEquals(date(DateTime::$FORMATS['short']), $this->date->format()); } public function test_to_string() { - $this->assert_equals(date(DateTime::get_format()), "" . $this->date); + $this->assertEquals(date(DateTime::get_format()), "" . $this->date); } public function test_create_from_format_error_handling() { $d = DateTime::createFromFormat('H:i:s Y-d-m', '!!!'); - $this->assert_false($d); + $this->assertFalse($d); } public function test_create_from_format_without_tz() { $d = DateTime::createFromFormat('H:i:s Y-d-m', '03:04:05 2000-02-01'); - $this->assert_equals(new DateTime('2000-01-02 03:04:05'), $d); + $this->assertEquals(new DateTime('2000-01-02 03:04:05'), $d); } public function test_create_from_format_with_tz() @@ -165,7 +165,7 @@ public function test_create_from_format_with_tz() $d = DateTime::createFromFormat('Y-m-d H:i:s', '2000-02-01 03:04:05', new \DateTimeZone('Etc/GMT-10')); $d2 = new DateTime('2000-01-31 17:04:05'); - $this->assert_equals($d2->getTimestamp(), $d->getTimestamp()); + $this->assertEquals($d2->getTimestamp(), $d->getTimestamp()); } public function test_native_date_time_attribute_copies_exact_tz() @@ -177,9 +177,9 @@ public function test_native_date_time_attribute_copies_exact_tz() $model->assign_attribute('updated_at', $dt); $dt2 = $model->read_attribute('updated_at'); - $this->assert_equals($dt->getTimestamp(), $dt2->getTimestamp()); - $this->assert_equals($dt->getTimeZone(), $dt2->getTimeZone()); - $this->assert_equals($dt->getTimeZone()->getName(), $dt2->getTimeZone()->getName()); + $this->assertEquals($dt->getTimestamp(), $dt2->getTimestamp()); + $this->assertEquals($dt->getTimeZone(), $dt2->getTimeZone()); + $this->assertEquals($dt->getTimeZone()->getName(), $dt2->getTimeZone()->getName()); } public function test_ar_date_time_attribute_copies_exact_tz() @@ -191,9 +191,9 @@ public function test_ar_date_time_attribute_copies_exact_tz() $model->assign_attribute('updated_at', $dt); $dt2 = $model->read_attribute('updated_at'); - $this->assert_equals($dt->getTimestamp(), $dt2->getTimestamp()); - $this->assert_equals($dt->getTimeZone(), $dt2->getTimeZone()); - $this->assert_equals($dt->getTimeZone()->getName(), $dt2->getTimeZone()->getName()); + $this->assertEquals($dt->getTimestamp(), $dt2->getTimestamp()); + $this->assertEquals($dt->getTimeZone(), $dt2->getTimeZone()); + $this->assertEquals($dt->getTimeZone()->getName(), $dt2->getTimeZone()->getName()); } public function test_clone() @@ -207,20 +207,20 @@ public function test_clone() $cloned_datetime = clone $datetime; // Assert initial state - $this->assert_false($model->attribute_is_dirty($model_attribute)); + $this->assertFalse($model->attribute_is_dirty($model_attribute)); $cloned_datetime->add(new DateInterval('PT1S')); // Assert that modifying the cloned object didn't flag the model - $this->assert_false($model->attribute_is_dirty($model_attribute)); + $this->assertFalse($model->attribute_is_dirty($model_attribute)); $datetime->add(new DateInterval('PT1S')); // Assert that modifying the model-attached object did flag the model - $this->assert_true($model->attribute_is_dirty($model_attribute)); + $this->assertTrue($model->attribute_is_dirty($model_attribute)); // Assert that the dates are equal but not the same instance - $this->assert_equals($datetime, $cloned_datetime); - $this->assert_not_same($datetime, $cloned_datetime); + $this->assertEquals($datetime, $cloned_datetime); + $this->assertNotSame($datetime, $cloned_datetime); } } diff --git a/test/ExpressionsTest.php b/test/ExpressionsTest.php index c1d90aab3..fc0868900 100644 --- a/test/ExpressionsTest.php +++ b/test/ExpressionsTest.php @@ -4,51 +4,51 @@ use ActiveRecord\ConnectionManager; use ActiveRecord\DatabaseException; -class ExpressionsTest extends SnakeCase_PHPUnit_Framework_TestCase +class ExpressionsTest extends TestCase { public function test_values() { $c = new Expressions(null,'a=? and b=?',1,2); - $this->assert_equals(array(1,2), $c->values()); + $this->assertEquals(array(1,2), $c->values()); } public function test_one_variable() { $c = new Expressions(null,'name=?','Tito'); - $this->assert_equals('name=?',$c->to_s()); - $this->assert_equals(array('Tito'),$c->values()); + $this->assertEquals('name=?',$c->to_s()); + $this->assertEquals(array('Tito'),$c->values()); } public function test_array_variable() { $c = new Expressions(null,'name IN(?) and id=?',array('Tito','George'),1); - $this->assert_equals(array(array('Tito','George'),1),$c->values()); + $this->assertEquals(array(array('Tito','George'),1),$c->values()); } public function test_multiple_variables() { $c = new Expressions(null,'name=? and book=?','Tito','Sharks'); - $this->assert_equals('name=? and book=?',$c->to_s()); - $this->assert_equals(array('Tito','Sharks'),$c->values()); + $this->assertEquals('name=? and book=?',$c->to_s()); + $this->assertEquals(array('Tito','Sharks'),$c->values()); } public function test_to_string() { $c = new Expressions(null,'name=? and book=?','Tito','Sharks'); - $this->assert_equals('name=? and book=?',$c->to_s()); + $this->assertEquals('name=? and book=?',$c->to_s()); } public function test_to_string_with_array_variable() { $c = new Expressions(null,'name IN(?) and id=?',array('Tito','George'),1); - $this->assert_equals('name IN(?,?) and id=?',$c->to_s()); + $this->assertEquals('name IN(?,?) and id=?',$c->to_s()); } public function test_to_string_with_null_options() { $c = new Expressions(null,'name=? and book=?','Tito','Sharks'); $x = null; - $this->assert_equals('name=? and book=?',$c->to_s(false,$x)); + $this->assertEquals('name=? and book=?',$c->to_s(false,$x)); } /** @@ -63,77 +63,77 @@ public function test_insufficient_variables() public function test_no_values() { $c = new Expressions(null,"name='Tito'"); - $this->assert_equals("name='Tito'",$c->to_s()); - $this->assert_equals(0,count($c->values())); + $this->assertEquals("name='Tito'",$c->to_s()); + $this->assertEquals(0,count($c->values())); } public function test_null_variable() { $a = new Expressions(null,'name=?',null); - $this->assert_equals('name=?',$a->to_s()); - $this->assert_equals(array(null),$a->values()); + $this->assertEquals('name=?',$a->to_s()); + $this->assertEquals(array(null),$a->values()); } public function test_zero_variable() { $a = new Expressions(null,'name=?',0); - $this->assert_equals('name=?',$a->to_s()); - $this->assert_equals(array(0),$a->values()); + $this->assertEquals('name=?',$a->to_s()); + $this->assertEquals(array(0),$a->values()); } public function test_empty_array_variable() { $a = new Expressions(null,'id IN(?)',array()); - $this->assert_equals('id IN(?)',$a->to_s()); - $this->assert_equals(array(array()),$a->values()); + $this->assertEquals('id IN(?)',$a->to_s()); + $this->assertEquals(array(array()),$a->values()); } public function test_ignore_invalid_parameter_marker() { $a = new Expressions(null,"question='Do you love backslashes?' and id in(?)",array(1,2)); - $this->assert_equals("question='Do you love backslashes?' and id in(?,?)",$a->to_s()); + $this->assertEquals("question='Do you love backslashes?' and id in(?,?)",$a->to_s()); } public function test_ignore_parameter_marker_with_escaped_quote() { $a = new Expressions(null,"question='Do you love''s backslashes?' and id in(?)",array(1,2)); - $this->assert_equals("question='Do you love''s backslashes?' and id in(?,?)",$a->to_s()); + $this->assertEquals("question='Do you love''s backslashes?' and id in(?,?)",$a->to_s()); } public function test_ignore_parameter_marker_with_backspace_escaped_quote() { $a = new Expressions(null,"question='Do you love\\'s backslashes?' and id in(?)",array(1,2)); - $this->assert_equals("question='Do you love\\'s backslashes?' and id in(?,?)",$a->to_s()); + $this->assertEquals("question='Do you love\\'s backslashes?' and id in(?,?)",$a->to_s()); } public function test_substitute() { $a = new Expressions(null,'name=? and id=?','Tito',1); - $this->assert_equals("name='Tito' and id=1",$a->to_s(true)); + $this->assertEquals("name='Tito' and id=1",$a->to_s(true)); } public function test_substitute_quotes_scalars_but_not_others() { $a = new Expressions(null,'id in(?)',array(1,'2',3.5)); - $this->assert_equals("id in(1,'2',3.5)",$a->to_s(true)); + $this->assertEquals("id in(1,'2',3.5)",$a->to_s(true)); } public function test_substitute_where_value_has_question_mark() { $a = new Expressions(null,'name=? and id=?','??????',1); - $this->assert_equals("name='??????' and id=1",$a->to_s(true)); + $this->assertEquals("name='??????' and id=1",$a->to_s(true)); } public function test_substitute_array_value() { $a = new Expressions(null,'id in(?)',array(1,2)); - $this->assert_equals("id in(1,2)",$a->to_s(true)); + $this->assertEquals("id in(1,2)",$a->to_s(true)); } public function test_substitute_escapes_quotes() { $a = new Expressions(null,'name=? or name in(?)',"Tito's Guild",array(1,"Tito's Guild")); - $this->assert_equals("name='Tito''s Guild' or name in(1,'Tito''s Guild')",$a->to_s(true)); + $this->assertEquals("name='Tito''s Guild' or name in(1,'Tito''s Guild')",$a->to_s(true)); } public function test_substitute_escape_quotes_with_connections_escape_method() @@ -141,26 +141,26 @@ public function test_substitute_escape_quotes_with_connections_escape_method() try { $conn = ConnectionManager::get_connection(); } catch (DatabaseException $e) { - $this->mark_test_skipped('failed to connect. '.$e->getMessage()); + $this->markTestSkipped('failed to connect. '.$e->getMessage()); } $a = new Expressions(null,'name=?',"Tito's Guild"); $a->set_connection($conn); $escaped = $conn->escape("Tito's Guild"); - $this->assert_equals("name=$escaped",$a->to_s(true)); + $this->assertEquals("name=$escaped",$a->to_s(true)); } public function test_bind() { $a = new Expressions(null,'name=? and id=?','Tito'); $a->bind(2,1); - $this->assert_equals(array('Tito',1),$a->values()); + $this->assertEquals(array('Tito',1),$a->values()); } public function test_bind_overwrite_existing() { $a = new Expressions(null,'name=? and id=?','Tito',1); $a->bind(2,99); - $this->assert_equals(array('Tito',99),$a->values()); + $this->assertEquals(array('Tito',99),$a->values()); } /** @@ -175,32 +175,32 @@ public function test_bind_invalid_parameter_number() public function test_subsitute_using_alternate_values() { $a = new Expressions(null,'name=?','Tito'); - $this->assert_equals("name='Tito'",$a->to_s(true)); + $this->assertEquals("name='Tito'",$a->to_s(true)); $x = array('values' => array('Hocus')); - $this->assert_equals("name='Hocus'",$a->to_s(true,$x)); + $this->assertEquals("name='Hocus'",$a->to_s(true,$x)); } public function test_null_value() { $a = new Expressions(null,'name=?',null); - $this->assert_equals('name=NULL',$a->to_s(true)); + $this->assertEquals('name=NULL',$a->to_s(true)); } public function test_hash_with_default_glue() { $a = new Expressions(null,array('id' => 1, 'name' => 'Tito')); - $this->assert_equals('id=? AND name=?',$a->to_s()); + $this->assertEquals('id=? AND name=?',$a->to_s()); } public function test_hash_with_glue() { $a = new Expressions(null,array('id' => 1, 'name' => 'Tito'),', '); - $this->assert_equals('id=?, name=?',$a->to_s()); + $this->assertEquals('id=?, name=?',$a->to_s()); } public function test_hash_with_array() { $a = new Expressions(null,array('id' => 1, 'name' => array('Tito','Mexican'))); - $this->assert_equals('id=? AND name IN(?,?)',$a->to_s()); + $this->assertEquals('id=? AND name IN(?,?)',$a->to_s()); } } diff --git a/test/HasManyThroughTest.php b/test/HasManyThroughTest.php index 1dcbdf3c3..ded8852a2 100644 --- a/test/HasManyThroughTest.php +++ b/test/HasManyThroughTest.php @@ -11,13 +11,13 @@ public function test_gh101_has_many_through() $user = User::find(1); $newsletter = Newsletter::find(1); - $this->assert_equals($newsletter->id, $user->newsletters[0]->id); - $this->assert_equals( + $this->assertEquals($newsletter->id, $user->newsletters[0]->id); + $this->assertEquals( 'foo\bar\biz\Newsletter', get_class($user->newsletters[0]) ); - $this->assert_equals($user->id, $newsletter->users[0]->id); - $this->assert_equals( + $this->assertEquals($user->id, $newsletter->users[0]->id); + $this->assertEquals( 'foo\bar\biz\User', get_class($newsletter->users[0]) ); @@ -31,17 +31,17 @@ public function test_gh101_has_many_through_include() ) )); - $this->assert_equals(1, $user->id); - $this->assert_equals(1, $user->user_newsletters[0]->id); + $this->assertEquals(1, $user->id); + $this->assertEquals(1, $user->user_newsletters[0]->id); } public function test_gh107_has_many_through_include_eager() { $venue = Venue::find(1, array('include' => array('events'))); - $this->assert_equals(1, $venue->events[0]->id); + $this->assertEquals(1, $venue->events[0]->id); $venue = Venue::find(1, array('include' => array('hosts'))); - $this->assert_equals(1, $venue->hosts[0]->id); + $this->assertEquals(1, $venue->hosts[0]->id); } public function test_gh107_has_many_though_include_eager_with_namespace() @@ -52,8 +52,8 @@ public function test_gh107_has_many_though_include_eager_with_namespace() ) )); - $this->assert_equals(1, $user->id); - $this->assert_equals(1, $user->newsletters[0]->id); + $this->assertEquals(1, $user->id); + $this->assertEquals(1, $user->newsletters[0]->id); } public function test_gh68_has_many_through_with_missing_associations() diff --git a/test/InflectorTest.php b/test/InflectorTest.php index d93f40b38..e4199ab92 100644 --- a/test/InflectorTest.php +++ b/test/InflectorTest.php @@ -1,27 +1,27 @@ inflector = ActiveRecord\Inflector::instance(); } public function test_underscorify() { - $this->assert_equals('rm__name__bob',$this->inflector->variablize('rm--name bob')); - $this->assert_equals('One_Two_Three',$this->inflector->underscorify('OneTwoThree')); + $this->assertEquals('rm__name__bob',$this->inflector->variablize('rm--name bob')); + $this->assertEquals('One_Two_Three',$this->inflector->underscorify('OneTwoThree')); } public function test_tableize() { - $this->assert_equals('angry_people',$this->inflector->tableize('AngryPerson')); - $this->assert_equals('my_sqls',$this->inflector->tableize('MySQL')); + $this->assertEquals('angry_people',$this->inflector->tableize('AngryPerson')); + $this->assertEquals('my_sqls',$this->inflector->tableize('MySQL')); } public function test_keyify() { - $this->assert_equals('building_type_id', $this->inflector->keyify('BuildingType')); + $this->assertEquals('building_type_id', $this->inflector->keyify('BuildingType')); } } diff --git a/test/ModelCallbackTest.php b/test/ModelCallbackTest.php index b9ffd7466..e2d26f9fe 100644 --- a/test/ModelCallbackTest.php +++ b/test/ModelCallbackTest.php @@ -2,9 +2,9 @@ class ModelCallbackTest extends DatabaseTest { - public function set_up($connection_name=null) + public function setUp($connection_name=null) { - parent::set_up($connection_name); + parent::setUp($connection_name); $this->venue = new Venue(); $this->callback = Venue::table()->callback; @@ -24,19 +24,19 @@ public function register_and_invoke_callbacks($callbacks, $return, $closure) return array_intersect($callbacks,$fired); } - public function assert_fires($callbacks, $closure) + public function assertFires($callbacks, $closure) { $executed = $this->register_and_invoke_callbacks($callbacks,true,$closure); - $this->assert_equals(count($callbacks),count($executed)); + $this->assertEquals(count($callbacks),count($executed)); } - public function assert_does_not_fire($callbacks, $closure) + public function assertDoesNotFire($callbacks, $closure) { $executed = $this->register_and_invoke_callbacks($callbacks,true,$closure); - $this->assert_equals(0,count($executed)); + $this->assertEquals(0,count($executed)); } - public function assert_fires_returns_false($callbacks, $only_fire, $closure) + public function assertFiresReturnsFalse($callbacks, $only_fire, $closure) { if (!is_array($only_fire)) $only_fire = array($only_fire); @@ -45,52 +45,52 @@ public function assert_fires_returns_false($callbacks, $only_fire, $closure) sort($only_fire); $intersect = array_intersect($only_fire,$executed); sort($intersect); - $this->assert_equals($only_fire,$intersect); + $this->assertEquals($only_fire,$intersect); } public function test_after_construct_fires_by_default() { - $this->assert_fires('after_construct',function($model) { new Venue(); }); + $this->assertFires('after_construct',function($model) { new Venue(); }); } public function test_fire_validation_callbacks_on_insert() { - $this->assert_fires(array('before_validation','after_validation','before_validation_on_create','after_validation_on_create'), + $this->assertFires(array('before_validation','after_validation','before_validation_on_create','after_validation_on_create'), function($model) { $model = new Venue(); $model->save(); }); } public function test_fire_validation_callbacks_on_update() { - $this->assert_fires(array('before_validation','after_validation','before_validation_on_update','after_validation_on_update'), + $this->assertFires(array('before_validation','after_validation','before_validation_on_update','after_validation_on_update'), function($model) { $model = Venue::first(); $model->save(); }); } public function test_validation_call_backs_not_fired_due_to_bypassing_validations() { - $this->assert_does_not_fire('before_validation',function($model) { $model->save(false); }); + $this->assertDoesNotFire('before_validation',function($model) { $model->save(false); }); } public function test_before_validation_returning_false_cancels_callbacks() { - $this->assert_fires_returns_false(array('before_validation','after_validation'),'before_validation', + $this->assertFiresReturnsFalse(array('before_validation','after_validation'),'before_validation', function($model) { $model->save(); }); } public function test_fires_before_save_and_before_update_when_updating() { - $this->assert_fires(array('before_save','before_update'), + $this->assertFires(array('before_save','before_update'), function($model) { $model = Venue::first(); $model->name = "something new"; $model->save(); }); } public function test_before_save_returning_false_cancels_callbacks() { - $this->assert_fires_returns_false(array('before_save','before_create'),'before_save', + $this->assertFiresReturnsFalse(array('before_save','before_create'),'before_save', function($model) { $model = new Venue(); $model->save(); }); } public function test_destroy() { - $this->assert_fires(array('before_destroy','after_destroy'), + $this->assertFires(array('before_destroy','after_destroy'), function($model) { $model->delete(); }); } } diff --git a/test/MysqlAdapterTest.php b/test/MysqlAdapterTest.php index f7153eea8..9e0d09ed3 100644 --- a/test/MysqlAdapterTest.php +++ b/test/MysqlAdapterTest.php @@ -5,17 +5,17 @@ class MysqlAdapterTest extends AdapterTest { - public function set_up($connection_name=null) + public function setUp($connection_name=null) { - parent::set_up('mysql'); + parent::setUp('mysql'); } public function test_enum() { $author_columns = $this->conn->columns('authors'); - $this->assert_equals('enum',$author_columns['some_enum']->raw_type); - $this->assert_equals(Column::STRING,$author_columns['some_enum']->type); - $this->assert_same(null,$author_columns['some_enum']->length); + $this->assertEquals('enum',$author_columns['some_enum']->raw_type); + $this->assertEquals(Column::STRING,$author_columns['some_enum']->type); + $this->assertSame(null,$author_columns['some_enum']->length); } public function test_set_charset() @@ -23,7 +23,7 @@ public function test_set_charset() $connection_info = ActiveRecord\Config::instance()->get_connection_info($this->connection_name); $connection_info->charset = 'utf8'; $conn = ActiveRecord\Connection::instance($connection_info); - $this->assert_equals('SET NAMES ?', $conn->last_query); + $this->assertEquals('SET NAMES ?', $conn->last_query); } public function test_limit_with_null_offset_does_not_contain_offset() @@ -32,6 +32,6 @@ public function test_limit_with_null_offset_does_not_contain_offset() $sql = 'SELECT * FROM authors ORDER BY name ASC'; $this->conn->query_and_fetch($this->conn->limit($sql,null,1),function($row) use (&$ret) { $ret[] = $row; }); - $this->assert_true(strpos($this->conn->last_query, 'LIMIT 1') !== false); + $this->assertTrue(strpos($this->conn->last_query, 'LIMIT 1') !== false); } } diff --git a/test/OciAdapterTest.php b/test/OciAdapterTest.php index 2a8fa7376..4f4d522a3 100644 --- a/test/OciAdapterTest.php +++ b/test/OciAdapterTest.php @@ -3,31 +3,31 @@ class OciAdapterTest extends AdapterTest { - public function set_up($connection_name=null) + public function setUp($connection_name=null) { - parent::set_up('oci'); + parent::setUp('oci'); } public function test_get_sequence_name() { - $this->assert_equals('authors_seq',$this->conn->get_sequence_name('authors','author_id')); + $this->assertEquals('authors_seq',$this->conn->get_sequence_name('authors','author_id')); } public function test_columns_text() { $author_columns = $this->conn->columns('authors'); - $this->assert_equals('varchar2',$author_columns['some_text']->raw_type); - $this->assert_equals(100,$author_columns['some_text']->length); + $this->assertEquals('varchar2',$author_columns['some_text']->raw_type); + $this->assertEquals(100,$author_columns['some_text']->length); } public function test_datetime_to_string() { - $this->assert_equals('01-Jan-2009 01:01:01 AM',$this->conn->datetime_to_string(date_create('2009-01-01 01:01:01 EST'))); + $this->assertEquals('01-Jan-2009 01:01:01 AM',$this->conn->datetime_to_string(date_create('2009-01-01 01:01:01 EST'))); } public function test_date_to_string() { - $this->assert_equals('01-Jan-2009',$this->conn->date_to_string(date_create('2009-01-01 01:01:01 EST'))); + $this->assertEquals('01-Jan-2009',$this->conn->date_to_string(date_create('2009-01-01 01:01:01 EST'))); } public function test_insert_id() {} @@ -41,6 +41,6 @@ public function test_set_charset() $connection_info = ActiveRecord\Config::instance()->get_connection_info($this->connection_name); $connection_info->charset = 'utf8'; $conn = ActiveRecord\Connection::instance($connection_info); - $this->assert_equals(';charset=utf8', $conn->dsn_params); + $this->assertEquals(';charset=utf8', $conn->dsn_params); } } diff --git a/test/PgsqlAdapterTest.php b/test/PgsqlAdapterTest.php index c7d23a594..119ee5ad0 100644 --- a/test/PgsqlAdapterTest.php +++ b/test/PgsqlAdapterTest.php @@ -5,28 +5,28 @@ class PgsqlAdapterTest extends AdapterTest { - public function set_up($connection_name=null) + public function setUp($connection_name=null) { - parent::set_up('pgsql'); + parent::setUp('pgsql'); } public function test_insert_id() { $this->conn->query("INSERT INTO authors(author_id,name) VALUES(nextval('authors_author_id_seq'),'name')"); - $this->assert_true($this->conn->insert_id('authors_author_id_seq') > 0); + $this->assertTrue($this->conn->insert_id('authors_author_id_seq') > 0); } public function test_insert_id_with_params() { $x = array('name'); $this->conn->query("INSERT INTO authors(author_id,name) VALUES(nextval('authors_author_id_seq'),?)",$x); - $this->assert_true($this->conn->insert_id('authors_author_id_seq') > 0); + $this->assertTrue($this->conn->insert_id('authors_author_id_seq') > 0); } public function test_insert_id_should_return_explicitly_inserted_id() { $this->conn->query('INSERT INTO authors(author_id,name) VALUES(99,\'name\')'); - $this->assert_true($this->conn->insert_id('authors_author_id_seq') > 0); + $this->assertTrue($this->conn->insert_id('authors_author_id_seq') > 0); } public function test_set_charset() @@ -34,31 +34,31 @@ public function test_set_charset() $connection_info = ActiveRecord\Config::instance()->get_connection_info($this->connection_name); $connection_info->charset = 'utf8'; $conn = ActiveRecord\Connection::instance($connection_info); - $this->assert_equals("SET NAMES 'utf8'",$conn->last_query); + $this->assertEquals("SET NAMES 'utf8'",$conn->last_query); } public function test_gh96_columns_not_duplicated_by_index() { - $this->assert_equals(3,$this->conn->query_column_info("user_newsletters")->rowCount()); + $this->assertEquals(3,$this->conn->query_column_info("user_newsletters")->rowCount()); } public function test_boolean_to_string() { // false values - $this->assert_equals("0", $this->conn->boolean_to_string(false)); - $this->assert_equals("0", $this->conn->boolean_to_string('0')); - $this->assert_equals("0", $this->conn->boolean_to_string('f')); - $this->assert_equals("0", $this->conn->boolean_to_string('false')); - $this->assert_equals("0", $this->conn->boolean_to_string('n')); - $this->assert_equals("0", $this->conn->boolean_to_string('no')); - $this->assert_equals("0", $this->conn->boolean_to_string('off')); + $this->assertEquals("0", $this->conn->boolean_to_string(false)); + $this->assertEquals("0", $this->conn->boolean_to_string('0')); + $this->assertEquals("0", $this->conn->boolean_to_string('f')); + $this->assertEquals("0", $this->conn->boolean_to_string('false')); + $this->assertEquals("0", $this->conn->boolean_to_string('n')); + $this->assertEquals("0", $this->conn->boolean_to_string('no')); + $this->assertEquals("0", $this->conn->boolean_to_string('off')); // true values - $this->assert_equals("1", $this->conn->boolean_to_string(true)); - $this->assert_equals("1", $this->conn->boolean_to_string('1')); - $this->assert_equals("1", $this->conn->boolean_to_string('t')); - $this->assert_equals("1", $this->conn->boolean_to_string('true')); - $this->assert_equals("1", $this->conn->boolean_to_string('y')); - $this->assert_equals("1", $this->conn->boolean_to_string('yes')); - $this->assert_equals("1", $this->conn->boolean_to_string('on')); + $this->assertEquals("1", $this->conn->boolean_to_string(true)); + $this->assertEquals("1", $this->conn->boolean_to_string('1')); + $this->assertEquals("1", $this->conn->boolean_to_string('t')); + $this->assertEquals("1", $this->conn->boolean_to_string('true')); + $this->assertEquals("1", $this->conn->boolean_to_string('y')); + $this->assertEquals("1", $this->conn->boolean_to_string('yes')); + $this->assertEquals("1", $this->conn->boolean_to_string('on')); } } diff --git a/test/RelationshipTest.php b/test/RelationshipTest.php index 6adce031d..ffd54ef69 100644 --- a/test/RelationshipTest.php +++ b/test/RelationshipTest.php @@ -14,9 +14,9 @@ class RelationshipTest extends DatabaseTest protected $relationship_name; protected $relationship_names = array('has_many', 'belongs_to', 'has_one'); - public function set_up($connection_name=null) + public function setUp($connection_name=null) { - parent::set_up($connection_name); + parent::setUp($connection_name); Event::$belongs_to = array(array('venue'), array('host')); Venue::$has_many = array(array('events', 'order' => 'id asc'),array('hosts', 'through' => 'events', 'order' => 'hosts.id asc')); @@ -54,31 +54,31 @@ protected function get_relationship($type=null) return $ret; } - protected function assert_default_belongs_to($event, $association_name='venue') + protected function assertDefaultBelongsTo($event, $association_name='venue') { - $this->assert_true($event->$association_name instanceof Venue); - $this->assert_equals(5,$event->id); - $this->assert_equals('West Chester',$event->$association_name->city); - $this->assert_equals(6,$event->$association_name->id); + $this->assertTrue($event->$association_name instanceof Venue); + $this->assertEquals(5,$event->id); + $this->assertEquals('West Chester',$event->$association_name->city); + $this->assertEquals(6,$event->$association_name->id); } - protected function assert_default_has_many($venue, $association_name='events') + protected function assertDefaultHasMany($venue, $association_name='events') { - $this->assert_equals(2,$venue->id); - $this->assert_true(count($venue->$association_name) > 1); - $this->assert_equals('Yeah Yeah Yeahs',$venue->{$association_name}[0]->title); + $this->assertEquals(2,$venue->id); + $this->assertTrue(count($venue->$association_name) > 1); + $this->assertEquals('Yeah Yeah Yeahs',$venue->{$association_name}[0]->title); } - protected function assert_default_has_one($employee, $association_name='position') + protected function assertDefaultHasOne($employee, $association_name='position') { - $this->assert_true($employee->$association_name instanceof Position); - $this->assert_equals('physicist',$employee->$association_name->title); - $this->assert_not_null($employee->id, $employee->$association_name->title); + $this->assertTrue($employee->$association_name instanceof Position); + $this->assertEquals('physicist',$employee->$association_name->title); + $this->assertNotNull($employee->id, $employee->$association_name->title); } public function test_has_many_basic() { - $this->assert_default_has_many($this->get_relationship()); + $this->assertDefaultHasMany($this->get_relationship()); } public function test_eager_load_with_empty_nested_includes() @@ -86,7 +86,7 @@ public function test_eager_load_with_empty_nested_includes() $conditions['include'] = array('events'=>array()); Venue::find(2, $conditions); - $this->assert_sql_has("WHERE venue_id IN(?)", ActiveRecord\Table::load('Event')->last_sql); + $this->assertSqlHas("WHERE venue_id IN(?)", ActiveRecord\Table::load('Event')->last_sql); } public function test_gh_256_eager_loading_three_levels_deep() @@ -119,38 +119,38 @@ public function test_joins_on_model_via_undeclared_association() public function test_joins_only_loads_given_model_attributes() { $x = Event::first(array('joins' => array('venue'))); - $this->assert_sql_has('SELECT events.*',Event::table()->last_sql); - $this->assert_false(array_key_exists('city', $x->attributes())); + $this->assertSqlHas('SELECT events.*',Event::table()->last_sql); + $this->assertFalse(array_key_exists('city', $x->attributes())); } public function test_joins_combined_with_select_loads_all_attributes() { $x = Event::first(array('select' => 'events.*, venues.city as venue_city', 'joins' => array('venue'))); - $this->assert_sql_has('SELECT events.*, venues.city as venue_city',Event::table()->last_sql); - $this->assert_true(array_key_exists('venue_city', $x->attributes())); + $this->assertSqlHas('SELECT events.*, venues.city as venue_city',Event::table()->last_sql); + $this->assertTrue(array_key_exists('venue_city', $x->attributes())); } public function test_belongs_to_basic() { - $this->assert_default_belongs_to($this->get_relationship()); + $this->assertDefaultBelongsTo($this->get_relationship()); } public function test_belongs_to_returns_null_when_no_record() { $event = Event::find(6); - $this->assert_null($event->venue); + $this->assertNull($event->venue); } public function test_belongs_to_returns_null_when_foreign_key_is_null() { $event = Event::create(array('title' => 'venueless event')); - $this->assert_null($event->venue); + $this->assertNull($event->venue); } public function test_belongs_to_with_explicit_class_name() { Event::$belongs_to = array(array('explicit_class_name', 'class_name' => 'Venue')); - $this->assert_default_belongs_to($this->get_relationship(), 'explicit_class_name'); + $this->assertDefaultBelongsTo($this->get_relationship(), 'explicit_class_name'); } public function test_belongs_to_with_explicit_foreign_key() @@ -159,8 +159,8 @@ public function test_belongs_to_with_explicit_foreign_key() Book::$belongs_to = array(array('explicit_author', 'class_name' => 'Author', 'foreign_key' => 'secondary_author_id')); $book = Book::find(1); - $this->assert_equals(2, $book->secondary_author_id); - $this->assert_equals($book->secondary_author_id, $book->explicit_author->author_id); + $this->assertEquals(2, $book->secondary_author_id); + $this->assertEquals($book->secondary_author_id, $book->explicit_author->author_id); Book::$belongs_to = $old; } @@ -169,13 +169,13 @@ public function test_belongs_to_with_select() { Event::$belongs_to[0]['select'] = 'id, city'; $event = $this->get_relationship(); - $this->assert_default_belongs_to($event); + $this->assertDefaultBelongsTo($event); try { $event->venue->name; $this->fail('expected Exception ActiveRecord\UndefinedPropertyException'); } catch (ActiveRecord\UndefinedPropertyException $e) { - $this->assert_true(strpos($e->getMessage(), 'name') !== false); + $this->assertTrue(strpos($e->getMessage(), 'name') !== false); } } @@ -183,7 +183,7 @@ public function test_belongs_to_with_readonly() { Event::$belongs_to[0]['readonly'] = true; $event = $this->get_relationship(); - $this->assert_default_belongs_to($event); + $this->assertDefaultBelongsTo($event); try { $event->venue->save(); @@ -192,27 +192,27 @@ public function test_belongs_to_with_readonly() } $event->venue->name = 'new name'; - $this->assert_equals($event->venue->name, 'new name'); + $this->assertEquals($event->venue->name, 'new name'); } public function test_belongs_to_with_plural_attribute_name() { Event::$belongs_to = array(array('venues', 'class_name' => 'Venue')); - $this->assert_default_belongs_to($this->get_relationship(), 'venues'); + $this->assertDefaultBelongsTo($this->get_relationship(), 'venues'); } public function test_belongs_to_with_conditions_and_non_qualifying_record() { Event::$belongs_to[0]['conditions'] = "state = 'NY'"; $event = $this->get_relationship(); - $this->assert_equals(5,$event->id); - $this->assert_null($event->venue); + $this->assertEquals(5,$event->id); + $this->assertNull($event->venue); } public function test_belongs_to_with_conditions_and_qualifying_record() { Event::$belongs_to[0]['conditions'] = "state = 'PA'"; - $this->assert_default_belongs_to($this->get_relationship()); + $this->assertDefaultBelongsTo($this->get_relationship()); } public function test_belongs_to_build_association() @@ -220,14 +220,14 @@ public function test_belongs_to_build_association() $event = $this->get_relationship(); $values = array('city' => 'Richmond', 'state' => 'VA'); $venue = $event->build_venue($values); - $this->assert_equals($values, array_intersect_key($values, $venue->attributes())); + $this->assertEquals($values, array_intersect_key($values, $venue->attributes())); } public function test_has_many_build_association() { $author = Author::first(); - $this->assert_equals($author->id, $author->build_books()->author_id); - $this->assert_equals($author->id, $author->build_book()->author_id); + $this->assertEquals($author->id, $author->build_books()->author_id); + $this->assertEquals($author->id, $author->build_book()->author_id); } public function test_belongs_to_create_association() @@ -235,7 +235,7 @@ public function test_belongs_to_create_association() $event = $this->get_relationship(); $values = array('city' => 'Richmond', 'state' => 'VA', 'name' => 'Club 54', 'address' => '123 street'); $venue = $event->create_venue($values); - $this->assert_not_null($venue->id); + $this->assertNotNull($venue->id); } public function test_build_association_overwrites_guarded_foreign_keys() @@ -245,41 +245,41 @@ public function test_build_association_overwrites_guarded_foreign_keys() $book = $author->build_book(); - $this->assert_not_null($book->author_id); + $this->assertNotNull($book->author_id); } public function test_belongs_to_can_be_self_referential() { Author::$belongs_to = array(array('parent_author', 'class_name' => 'Author', 'foreign_key' => 'parent_author_id')); $author = Author::find(1); - $this->assert_equals(1, $author->id); - $this->assert_equals(3, $author->parent_author->id); + $this->assertEquals(1, $author->id); + $this->assertEquals(3, $author->parent_author->id); } public function test_belongs_to_with_an_invalid_option() { Event::$belongs_to[0]['joins'] = 'venue'; $event = Event::first()->venue; - $this->assert_sql_doesnt_has('INNER JOIN venues ON(events.venue_id = venues.id)',Event::table()->last_sql); + $this->assertSqlDoesntHas('INNER JOIN venues ON(events.venue_id = venues.id)',Event::table()->last_sql); } public function test_has_many_with_explicit_class_name() { Venue::$has_many = array(array('explicit_class_name', 'class_name' => 'Event', 'order' => 'id asc'));; - $this->assert_default_has_many($this->get_relationship(), 'explicit_class_name'); + $this->assertDefaultHasMany($this->get_relationship(), 'explicit_class_name'); } public function test_has_many_with_select() { Venue::$has_many[0]['select'] = 'title, type'; $venue = $this->get_relationship(); - $this->assert_default_has_many($venue); + $this->assertDefaultHasMany($venue); try { $venue->events[0]->description; $this->fail('expected Exception ActiveRecord\UndefinedPropertyException'); } catch (ActiveRecord\UndefinedPropertyException $e) { - $this->assert_true(strpos($e->getMessage(), 'description') !== false); + $this->assertTrue(strpos($e->getMessage(), 'description') !== false); } } @@ -287,7 +287,7 @@ public function test_has_many_with_readonly() { Venue::$has_many[0]['readonly'] = true; $venue = $this->get_relationship(); - $this->assert_default_has_many($venue); + $this->assertDefaultHasMany($venue); try { $venue->events[0]->save(); @@ -296,29 +296,29 @@ public function test_has_many_with_readonly() } $venue->events[0]->description = 'new desc'; - $this->assert_equals($venue->events[0]->description, 'new desc'); + $this->assertEquals($venue->events[0]->description, 'new desc'); } public function test_has_many_with_singular_attribute_name() { Venue::$has_many = array(array('event', 'class_name' => 'Event', 'order' => 'id asc')); - $this->assert_default_has_many($this->get_relationship(), 'event'); + $this->assertDefaultHasMany($this->get_relationship(), 'event'); } public function test_has_many_with_conditions_and_non_qualifying_record() { Venue::$has_many[0]['conditions'] = "title = 'pr0n @ railsconf'"; $venue = $this->get_relationship(); - $this->assert_equals(2,$venue->id); - $this->assert_true(empty($venue->events), is_array($venue->events)); + $this->assertEquals(2,$venue->id); + $this->assertTrue(empty($venue->events), is_array($venue->events)); } public function test_has_many_with_conditions_and_qualifying_record() { Venue::$has_many[0]['conditions'] = "title = 'Yeah Yeah Yeahs'"; $venue = $this->get_relationship(); - $this->assert_equals(2,$venue->id); - $this->assert_equals($venue->events[0]->title,'Yeah Yeah Yeahs'); + $this->assertEquals(2,$venue->id); + $this->assertEquals($venue->events[0]->title,'Yeah Yeah Yeahs'); } public function test_has_many_with_sql_clause_options() @@ -329,14 +329,14 @@ public function test_has_many_with_sql_clause_options() 'limit' => 2, 'offset' => 1); Venue::first()->events; - $this->assert_sql_has($this->conn->limit("SELECT type FROM events WHERE venue_id=? GROUP BY type",1,2),Event::table()->last_sql); + $this->assertSqlHas($this->conn->limit("SELECT type FROM events WHERE venue_id=? GROUP BY type",1,2),Event::table()->last_sql); } public function test_has_many_through() { $hosts = Venue::find(2)->hosts; - $this->assert_equals(2,$hosts[0]->id); - $this->assert_equals(3,$hosts[1]->id); + $this->assertEquals(2,$hosts[0]->id); + $this->assertEquals(3,$hosts[1]->id); } public function test_gh27_has_many_through_with_explicit_keys() @@ -351,8 +351,8 @@ public function test_gh27_has_many_through_with_explicit_keys() $property = Property::first(); - $this->assert_equals(1, $property->amenities[0]->amenity_id); - $this->assert_equals(2, $property->amenities[1]->amenity_id); + $this->assertEquals(1, $property->amenities[0]->amenity_id); + $this->assertEquals(2, $property->amenities[1]->amenity_id); } public function test_gh16_has_many_through_inside_a_loop_should_not_cause_an_exception() @@ -362,7 +362,7 @@ public function test_gh16_has_many_through_inside_a_loop_should_not_cause_an_exc foreach (Venue::all() as $venue) $count += count($venue->hosts); - $this->assert_true($count >= 5); + $this->assertTrue($count >= 5); } /** @@ -375,7 +375,7 @@ public function test_has_many_through_no_association() $venue = $this->get_relationship(); $n = $venue->hosts; - $this->assert_true(count($n) > 0); + $this->assertTrue(count($n) > 0); } public function test_has_many_through_with_select() @@ -384,8 +384,8 @@ public function test_has_many_through_with_select() Venue::$has_many[1] = array('hosts', 'through' => 'events', 'select' => 'hosts.*, events.*'); $venue = $this->get_relationship(); - $this->assert_true(count($venue->hosts) > 0); - $this->assert_not_null($venue->hosts[0]->title); + $this->assertTrue(count($venue->hosts) > 0); + $this->assertNotNull($venue->hosts[0]->title); } public function test_has_many_through_with_conditions() @@ -394,8 +394,8 @@ public function test_has_many_through_with_conditions() Venue::$has_many[1] = array('hosts', 'through' => 'events', 'conditions' => array('events.title != ?', 'Love Overboard')); $venue = $this->get_relationship(); - $this->assert_true(count($venue->hosts) === 1); - $this->assert_sql_has("events.title !=",ActiveRecord\Table::load('Host')->last_sql); + $this->assertTrue(count($venue->hosts) === 1); + $this->assertSqlHas("events.title !=",ActiveRecord\Table::load('Host')->last_sql); } public function test_has_many_through_using_source() @@ -404,7 +404,7 @@ public function test_has_many_through_using_source() Venue::$has_many[1] = array('hostess', 'through' => 'events', 'source' => 'host'); $venue = $this->get_relationship(); - $this->assert_true(count($venue->hostess) > 0); + $this->assertTrue(count($venue->hostess) > 0); } /** @@ -422,7 +422,7 @@ public function test_has_many_through_with_invalid_class_name() public function test_has_many_with_joins() { $x = Venue::first(array('joins' => array('events'))); - $this->assert_sql_has('INNER JOIN events ON(venues.id = events.venue_id)',Venue::table()->last_sql); + $this->assertSqlHas('INNER JOIN events ON(venues.id = events.venue_id)',Venue::table()->last_sql); } public function test_has_many_with_explicit_keys() @@ -432,34 +432,34 @@ public function test_has_many_with_explicit_keys() $author = Author::find(4); foreach ($author->explicit_books as $book) - $this->assert_equals($book->secondary_author_id, $author->parent_author_id); + $this->assertEquals($book->secondary_author_id, $author->parent_author_id); - $this->assert_true(strpos(ActiveRecord\Table::load('Book')->last_sql, "secondary_author_id") !== false); + $this->assertTrue(strpos(ActiveRecord\Table::load('Book')->last_sql, "secondary_author_id") !== false); Author::$has_many = $old; } public function test_has_one_basic() { - $this->assert_default_has_one($this->get_relationship()); + $this->assertDefaultHasOne($this->get_relationship()); } public function test_has_one_with_explicit_class_name() { Employee::$has_one = array(array('explicit_class_name', 'class_name' => 'Position')); - $this->assert_default_has_one($this->get_relationship(), 'explicit_class_name'); + $this->assertDefaultHasOne($this->get_relationship(), 'explicit_class_name'); } public function test_has_one_with_select() { Employee::$has_one[0]['select'] = 'title'; $employee = $this->get_relationship(); - $this->assert_default_has_one($employee); + $this->assertDefaultHasOne($employee); try { $employee->position->active; $this->fail('expected Exception ActiveRecord\UndefinedPropertyException'); } catch (ActiveRecord\UndefinedPropertyException $e) { - $this->assert_true(strpos($e->getMessage(), 'active') !== false); + $this->assertTrue(strpos($e->getMessage(), 'active') !== false); } } @@ -467,29 +467,29 @@ public function test_has_one_with_order() { Employee::$has_one[0]['order'] = 'title'; $employee = $this->get_relationship(); - $this->assert_default_has_one($employee); - $this->assert_sql_has('ORDER BY title',Position::table()->last_sql); + $this->assertDefaultHasOne($employee); + $this->assertSqlHas('ORDER BY title',Position::table()->last_sql); } public function test_has_one_with_conditions_and_non_qualifying_record() { Employee::$has_one[0]['conditions'] = "title = 'programmer'"; $employee = $this->get_relationship(); - $this->assert_equals(1,$employee->id); - $this->assert_null($employee->position); + $this->assertEquals(1,$employee->id); + $this->assertNull($employee->position); } public function test_has_one_with_conditions_and_qualifying_record() { Employee::$has_one[0]['conditions'] = "title = 'physicist'"; - $this->assert_default_has_one($this->get_relationship()); + $this->assertDefaultHasOne($this->get_relationship()); } public function test_has_one_with_readonly() { Employee::$has_one[0]['readonly'] = true; $employee = $this->get_relationship(); - $this->assert_default_has_one($employee); + $this->assertDefaultHasOne($employee); try { $employee->position->save(); @@ -498,21 +498,21 @@ public function test_has_one_with_readonly() } $employee->position->title = 'new title'; - $this->assert_equals($employee->position->title, 'new title'); + $this->assertEquals($employee->position->title, 'new title'); } public function test_has_one_can_be_self_referential() { Author::$has_one[1] = array('parent_author', 'class_name' => 'Author', 'foreign_key' => 'parent_author_id'); $author = Author::find(1); - $this->assert_equals(1, $author->id); - $this->assert_equals(3, $author->parent_author->id); + $this->assertEquals(1, $author->id); + $this->assertEquals(3, $author->parent_author->id); } public function test_has_one_with_joins() { $x = Employee::first(array('joins' => array('position'))); - $this->assert_sql_has('INNER JOIN positions ON(employees.id = positions.employee_id)',Employee::table()->last_sql); + $this->assertSqlHas('INNER JOIN positions ON(employees.id = positions.employee_id)',Employee::table()->last_sql); } public function test_has_one_with_explicit_keys() @@ -520,27 +520,27 @@ public function test_has_one_with_explicit_keys() Book::$has_one = array(array('explicit_author', 'class_name' => 'Author', 'foreign_key' => 'parent_author_id', 'primary_key' => 'secondary_author_id')); $book = Book::find(1); - $this->assert_equals($book->secondary_author_id, $book->explicit_author->parent_author_id); - $this->assert_true(strpos(ActiveRecord\Table::load('Author')->last_sql, "parent_author_id") !== false); + $this->assertEquals($book->secondary_author_id, $book->explicit_author->parent_author_id); + $this->assertTrue(strpos(ActiveRecord\Table::load('Author')->last_sql, "parent_author_id") !== false); } public function test_dont_attempt_to_load_if_all_foreign_keys_are_null() { $event = new Event(); $event->venue; - $this->assert_sql_doesnt_has($this->conn->last_query,'is IS NULL'); + $this->assertSqlDoesntHas($this->conn->last_query,'is IS NULL'); } public function test_relationship_on_table_with_underscores() { - $this->assert_equals(1,Author::find(1)->awesome_person->is_awesome); + $this->assertEquals(1,Author::find(1)->awesome_person->is_awesome); } public function test_has_one_through() { Venue::$has_many = array(array('events'),array('hosts', 'through' => 'events')); $venue = Venue::first(); - $this->assert_true(count($venue->hosts) > 0); + $this->assertTrue(count($venue->hosts) > 0); } /** @@ -556,19 +556,19 @@ public function test_gh93_and_gh100_eager_loading_respects_association_options() Venue::$has_many = array(array('events', 'class_name' => 'Event', 'order' => 'id asc', 'conditions' => array('length(title) = ?', 14))); $venues = Venue::find(array(2, 6), array('include' => 'events')); - $this->assert_sql_has("WHERE (length(title) = ?) AND (venue_id IN(?,?)) ORDER BY id asc",ActiveRecord\Table::load('Event')->last_sql); - $this->assert_equals(1, count($venues[0]->events)); + $this->assertSqlHas("WHERE (length(title) = ?) AND (venue_id IN(?,?)) ORDER BY id asc",ActiveRecord\Table::load('Event')->last_sql); + $this->assertEquals(1, count($venues[0]->events)); } public function test_eager_loading_has_many_x() { $venues = Venue::find(array(2, 6), array('include' => 'events')); - $this->assert_sql_has("WHERE venue_id IN(?,?)",ActiveRecord\Table::load('Event')->last_sql); + $this->assertSqlHas("WHERE venue_id IN(?,?)",ActiveRecord\Table::load('Event')->last_sql); foreach ($venues[0]->events as $event) - $this->assert_equals($event->venue_id, $venues[0]->id); + $this->assertEquals($event->venue_id, $venues[0]->id); - $this->assert_equals(2, count($venues[0]->events)); + $this->assertEquals(2, count($venues[0]->events)); } public function test_eager_loading_has_many_with_no_related_rows() @@ -576,10 +576,10 @@ public function test_eager_loading_has_many_with_no_related_rows() $venues = Venue::find(array(7, 8), array('include' => 'events')); foreach ($venues as $v) - $this->assert_true(empty($v->events)); + $this->assertTrue(empty($v->events)); - $this->assert_sql_has("WHERE id IN(?,?)",ActiveRecord\Table::load('Venue')->last_sql); - $this->assert_sql_has("WHERE venue_id IN(?,?)",ActiveRecord\Table::load('Event')->last_sql); + $this->assertSqlHas("WHERE id IN(?,?)",ActiveRecord\Table::load('Venue')->last_sql); + $this->assertSqlHas("WHERE venue_id IN(?,?)",ActiveRecord\Table::load('Event')->last_sql); } public function test_eager_loading_has_many_array_of_includes() @@ -591,43 +591,43 @@ public function test_eager_loading_has_many_array_of_includes() foreach ($assocs as $assoc) { - $this->assert_internal_type('array', $authors[0]->$assoc); + $this->assertInternalType('array', $authors[0]->$assoc); foreach ($authors[0]->$assoc as $a) - $this->assert_equals($authors[0]->author_id,$a->author_id); + $this->assertEquals($authors[0]->author_id,$a->author_id); } foreach ($assocs as $assoc) { - $this->assert_internal_type('array', $authors[1]->$assoc); - $this->assert_true(empty($authors[1]->$assoc)); + $this->assertInternalType('array', $authors[1]->$assoc); + $this->assertTrue(empty($authors[1]->$assoc)); } - $this->assert_sql_has("WHERE author_id IN(?,?)",ActiveRecord\Table::load('Author')->last_sql); - $this->assert_sql_has("WHERE author_id IN(?,?)",ActiveRecord\Table::load('Book')->last_sql); - $this->assert_sql_has("WHERE author_id IN(?,?)",ActiveRecord\Table::load('AwesomePerson')->last_sql); + $this->assertSqlHas("WHERE author_id IN(?,?)",ActiveRecord\Table::load('Author')->last_sql); + $this->assertSqlHas("WHERE author_id IN(?,?)",ActiveRecord\Table::load('Book')->last_sql); + $this->assertSqlHas("WHERE author_id IN(?,?)",ActiveRecord\Table::load('AwesomePerson')->last_sql); } public function test_eager_loading_has_many_nested() { $venues = Venue::find(array(1,2), array('include' => array('events' => array('host')))); - $this->assert_equals(2, count($venues)); + $this->assertEquals(2, count($venues)); foreach ($venues as $v) { - $this->assert_true(count($v->events) > 0); + $this->assertTrue(count($v->events) > 0); foreach ($v->events as $e) { - $this->assert_equals($e->host_id, $e->host->id); - $this->assert_equals($v->id, $e->venue_id); + $this->assertEquals($e->host_id, $e->host->id); + $this->assertEquals($v->id, $e->venue_id); } } - $this->assert_sql_has("WHERE id IN(?,?)",ActiveRecord\Table::load('Venue')->last_sql); - $this->assert_sql_has("WHERE venue_id IN(?,?)",ActiveRecord\Table::load('Event')->last_sql); - $this->assert_sql_has("WHERE id IN(?,?,?)",ActiveRecord\Table::load('Host')->last_sql); + $this->assertSqlHas("WHERE id IN(?,?)",ActiveRecord\Table::load('Venue')->last_sql); + $this->assertSqlHas("WHERE venue_id IN(?,?)",ActiveRecord\Table::load('Event')->last_sql); + $this->assertSqlHas("WHERE id IN(?,?,?)",ActiveRecord\Table::load('Host')->last_sql); } public function test_eager_loading_belongs_to() @@ -635,9 +635,9 @@ public function test_eager_loading_belongs_to() $events = Event::find(array(1,2,3,5,7), array('include' => 'venue')); foreach ($events as $event) - $this->assert_equals($event->venue_id, $event->venue->id); + $this->assertEquals($event->venue_id, $event->venue->id); - $this->assert_sql_has("WHERE id IN(?,?,?,?,?)",ActiveRecord\Table::load('Venue')->last_sql); + $this->assertSqlHas("WHERE id IN(?,?,?,?,?)",ActiveRecord\Table::load('Venue')->last_sql); } public function test_eager_loading_belongs_to_array_of_includes() @@ -646,13 +646,13 @@ public function test_eager_loading_belongs_to_array_of_includes() foreach ($events as $event) { - $this->assert_equals($event->venue_id, $event->venue->id); - $this->assert_equals($event->host_id, $event->host->id); + $this->assertEquals($event->venue_id, $event->venue->id); + $this->assertEquals($event->host_id, $event->host->id); } - $this->assert_sql_has("WHERE id IN(?,?,?,?,?)",ActiveRecord\Table::load('Event')->last_sql); - $this->assert_sql_has("WHERE id IN(?,?,?,?,?)",ActiveRecord\Table::load('Host')->last_sql); - $this->assert_sql_has("WHERE id IN(?,?,?,?,?)",ActiveRecord\Table::load('Venue')->last_sql); + $this->assertSqlHas("WHERE id IN(?,?,?,?,?)",ActiveRecord\Table::load('Event')->last_sql); + $this->assertSqlHas("WHERE id IN(?,?,?,?,?)",ActiveRecord\Table::load('Host')->last_sql); + $this->assertSqlHas("WHERE id IN(?,?,?,?,?)",ActiveRecord\Table::load('Venue')->last_sql); } public function test_eager_loading_belongs_to_nested() @@ -665,13 +665,13 @@ public function test_eager_loading_belongs_to_nested() foreach ($books as $book) { - $this->assert_equals($book->author_id,$book->author->author_id); - $this->assert_equals($book->author->author_id,$book->author->awesome_people[0]->author_id); + $this->assertEquals($book->author_id,$book->author->author_id); + $this->assertEquals($book->author->author_id,$book->author->awesome_people[0]->author_id); } - $this->assert_sql_has("WHERE book_id IN(?,?)",ActiveRecord\Table::load('Book')->last_sql); - $this->assert_sql_has("WHERE author_id IN(?,?)",ActiveRecord\Table::load('Author')->last_sql); - $this->assert_sql_has("WHERE author_id IN(?,?)",ActiveRecord\Table::load('AwesomePerson')->last_sql); + $this->assertSqlHas("WHERE book_id IN(?,?)",ActiveRecord\Table::load('Book')->last_sql); + $this->assertSqlHas("WHERE author_id IN(?,?)",ActiveRecord\Table::load('Author')->last_sql); + $this->assertSqlHas("WHERE author_id IN(?,?)",ActiveRecord\Table::load('AwesomePerson')->last_sql); } public function test_eager_loading_belongs_to_with_no_related_rows() @@ -682,10 +682,10 @@ public function test_eager_loading_belongs_to_with_no_related_rows() $events = Event::find(array($e1->id, $e2->id), array('include' => 'venue')); foreach ($events as $e) - $this->assert_null($e->venue); + $this->assertNull($e->venue); - $this->assert_sql_has("WHERE id IN(?,?)",ActiveRecord\Table::load('Event')->last_sql); - $this->assert_sql_has("WHERE id IN(?,?)",ActiveRecord\Table::load('Venue')->last_sql); + $this->assertSqlHas("WHERE id IN(?,?)",ActiveRecord\Table::load('Event')->last_sql); + $this->assertSqlHas("WHERE id IN(?,?)",ActiveRecord\Table::load('Venue')->last_sql); } public function test_eager_loading_clones_related_objects() @@ -695,9 +695,9 @@ public function test_eager_loading_clones_related_objects() $venue = $events[0]->venue; $venue->name = "new name"; - $this->assert_equals($venue->id, $events[1]->venue->id); - $this->assert_not_equals($venue->name, $events[1]->venue->name); - $this->assert_not_equals(spl_object_hash($venue), spl_object_hash($events[1]->venue)); + $this->assertEquals($venue->id, $events[1]->venue->id); + $this->assertNotEquals($venue->name, $events[1]->venue->name); + $this->assertNotEquals(spl_object_hash($venue), spl_object_hash($events[1]->venue)); } public function test_eager_loading_clones_nested_related_objects() @@ -708,9 +708,9 @@ public function test_eager_loading_clones_nested_related_objects() $changed_host = $venues[3]->events[0]->host; $changed_host->name = "changed"; - $this->assert_equals($changed_host->id, $unchanged_host->id); - $this->assert_not_equals($changed_host->name, $unchanged_host->name); - $this->assert_not_equals(spl_object_hash($changed_host), spl_object_hash($unchanged_host)); + $this->assertEquals($changed_host->id, $unchanged_host->id); + $this->assertNotEquals($changed_host->name, $unchanged_host->name); + $this->assertNotEquals(spl_object_hash($changed_host), spl_object_hash($unchanged_host)); } public function test_gh_23_relationships_with_joins_to_same_table_should_alias_table_name() @@ -728,9 +728,9 @@ public function test_gh_23_relationships_with_joins_to_same_table_should_alias_t $book = Book::find(2, array('joins' => array('to', 'from_', 'another'), 'select' => $select)); - $this->assert_not_null($book->from_author_name); - $this->assert_not_null($book->to_author_name); - $this->assert_not_null($book->another_author_name); + $this->assertNotNull($book->from_author_name); + $this->assertNotNull($book->to_author_name); + $this->assertNotNull($book->another_author_name); Book::$belongs_to = $old; } @@ -738,7 +738,7 @@ public function test_gh_40_relationships_with_joins_aliases_table_name_in_condit { $event = Event::find(1, array('joins' => array('venue'))); - $this->assert_equals($event->id, $event->venue->id); + $this->assertEquals($event->id, $event->venue->id); } /** diff --git a/test/SQLBuilderTest.php b/test/SQLBuilderTest.php index b44ca1c41..48e01d902 100644 --- a/test/SQLBuilderTest.php +++ b/test/SQLBuilderTest.php @@ -9,9 +9,9 @@ class SQLBuilderTest extends DatabaseTest protected $class_name = 'Author'; protected $table; - public function set_up($connection_name=null) + public function setUp($connection_name=null) { - parent::set_up($connection_name); + parent::setUp($connection_name); $this->sql = new SQLBuilder($this->conn,$this->table_name); $this->table = Table::load($this->class_name); } @@ -21,15 +21,15 @@ protected function cond_from_s($name, $values=null, $map=null) return SQLBuilder::create_conditions_from_underscored_string($this->table->conn, $name, $values, $map); } - public function assert_conditions($expected_sql, $values, $underscored_string, $map=null) + public function assertConditions($expected_sql, $values, $underscored_string, $map=null) { $cond = SQLBuilder::create_conditions_from_underscored_string($this->table->conn,$underscored_string,$values,$map); - $this->assert_sql_has($expected_sql,array_shift($cond)); + $this->assertSqlHas($expected_sql,array_shift($cond)); if ($values) - $this->assert_equals(array_values(array_filter($values,function($s) { return $s !== null; })),array_values($cond)); + $this->assertEquals(array_values(array_filter($values,function($s) { return $s !== null; })),array_values($cond)); else - $this->assert_equals(array(),$cond); + $this->assertEquals(array(),$cond); } /** @@ -42,84 +42,84 @@ public function test_no_connection() public function test_nothing() { - $this->assert_equals('SELECT * FROM authors',(string)$this->sql); + $this->assertEquals('SELECT * FROM authors',(string)$this->sql); } public function test_where_with_array() { $this->sql->where("id=? AND name IN(?)",1,array('Tito','Mexican')); - $this->assert_sql_has("SELECT * FROM authors WHERE id=? AND name IN(?,?)",(string)$this->sql); - $this->assert_equals(array(1,'Tito','Mexican'),$this->sql->get_where_values()); + $this->assertSqlHas("SELECT * FROM authors WHERE id=? AND name IN(?,?)",(string)$this->sql); + $this->assertEquals(array(1,'Tito','Mexican'),$this->sql->get_where_values()); } public function test_where_with_hash() { $this->sql->where(array('id' => 1, 'name' => 'Tito')); - $this->assert_sql_has("SELECT * FROM authors WHERE id=? AND name=?",(string)$this->sql); - $this->assert_equals(array(1,'Tito'),$this->sql->get_where_values()); + $this->assertSqlHas("SELECT * FROM authors WHERE id=? AND name=?",(string)$this->sql); + $this->assertEquals(array(1,'Tito'),$this->sql->get_where_values()); } public function test_where_with_hash_and_array() { $this->sql->where(array('id' => 1, 'name' => array('Tito','Mexican'))); - $this->assert_sql_has("SELECT * FROM authors WHERE id=? AND name IN(?,?)",(string)$this->sql); - $this->assert_equals(array(1,'Tito','Mexican'),$this->sql->get_where_values()); + $this->assertSqlHas("SELECT * FROM authors WHERE id=? AND name IN(?,?)",(string)$this->sql); + $this->assertEquals(array(1,'Tito','Mexican'),$this->sql->get_where_values()); } public function test_gh134_where_with_hash_and_null() { $this->sql->where(array('id' => 1, 'name' => null)); - $this->assert_sql_has("SELECT * FROM authors WHERE id=? AND name IS ?",(string)$this->sql); - $this->assert_equals(array(1, null),$this->sql->get_where_values()); + $this->assertSqlHas("SELECT * FROM authors WHERE id=? AND name IS ?",(string)$this->sql); + $this->assertEquals(array(1, null),$this->sql->get_where_values()); } public function test_where_with_null() { $this->sql->where(null); - $this->assert_equals('SELECT * FROM authors',(string)$this->sql); + $this->assertEquals('SELECT * FROM authors',(string)$this->sql); } public function test_where_with_no_args() { $this->sql->where(); - $this->assert_equals('SELECT * FROM authors',(string)$this->sql); + $this->assertEquals('SELECT * FROM authors',(string)$this->sql); } public function test_order() { $this->sql->order('name'); - $this->assert_equals('SELECT * FROM authors ORDER BY name',(string)$this->sql); + $this->assertEquals('SELECT * FROM authors ORDER BY name',(string)$this->sql); } public function test_limit() { $this->sql->limit(10)->offset(1); - $this->assert_equals($this->conn->limit('SELECT * FROM authors',1,10),(string)$this->sql); + $this->assertEquals($this->conn->limit('SELECT * FROM authors',1,10),(string)$this->sql); } public function test_select() { $this->sql->select('id,name'); - $this->assert_equals('SELECT id,name FROM authors',(string)$this->sql); + $this->assertEquals('SELECT id,name FROM authors',(string)$this->sql); } public function test_joins() { $join = 'inner join books on(authors.id=books.author_id)'; $this->sql->joins($join); - $this->assert_equals("SELECT * FROM authors $join",(string)$this->sql); + $this->assertEquals("SELECT * FROM authors $join",(string)$this->sql); } public function test_group() { $this->sql->group('name'); - $this->assert_equals('SELECT * FROM authors GROUP BY name',(string)$this->sql); + $this->assertEquals('SELECT * FROM authors GROUP BY name',(string)$this->sql); } public function test_having() { $this->sql->having("created_at > '2009-01-01'"); - $this->assert_equals("SELECT * FROM authors HAVING created_at > '2009-01-01'", (string)$this->sql); + $this->assertEquals("SELECT * FROM authors HAVING created_at > '2009-01-01'", (string)$this->sql); } public function test_all_clauses_after_where_should_be_correctly_ordered() @@ -129,7 +129,7 @@ public function test_all_clauses_after_where_should_be_correctly_ordered() $this->sql->order('name'); $this->sql->group('name'); $this->sql->where(array('id' => 1)); - $this->assert_sql_has($this->conn->limit("SELECT * FROM authors WHERE id=? GROUP BY name HAVING created_at > '2009-01-01' ORDER BY name",1,10), (string)$this->sql); + $this->assertSqlHas($this->conn->limit("SELECT * FROM authors WHERE id=? GROUP BY name HAVING created_at > '2009-01-01' ORDER BY name",1,10), (string)$this->sql); } /** @@ -143,122 +143,122 @@ public function test_insert_requires_hash() public function test_insert() { $this->sql->insert(array('id' => 1, 'name' => 'Tito')); - $this->assert_sql_has("INSERT INTO authors(id,name) VALUES(?,?)",(string)$this->sql); + $this->assertSqlHas("INSERT INTO authors(id,name) VALUES(?,?)",(string)$this->sql); } public function test_insert_with_null() { $this->sql->insert(array('id' => 1, 'name' => null)); - $this->assert_sql_has("INSERT INTO authors(id,name) VALUES(?,?)",$this->sql->to_s()); + $this->assertSqlHas("INSERT INTO authors(id,name) VALUES(?,?)",$this->sql->to_s()); } public function test_update_with_hash() { $this->sql->update(array('id' => 1, 'name' => 'Tito'))->where('id=1 AND name IN(?)',array('Tito','Mexican')); - $this->assert_sql_has("UPDATE authors SET id=?, name=? WHERE id=1 AND name IN(?,?)",(string)$this->sql); - $this->assert_equals(array(1,'Tito','Tito','Mexican'),$this->sql->bind_values()); + $this->assertSqlHas("UPDATE authors SET id=?, name=? WHERE id=1 AND name IN(?,?)",(string)$this->sql); + $this->assertEquals(array(1,'Tito','Tito','Mexican'),$this->sql->bind_values()); } public function test_update_with_limit_and_order() { if (!$this->conn->accepts_limit_and_order_for_update_and_delete()) - $this->mark_test_skipped('Only MySQL & Sqlite accept limit/order with UPDATE operation'); + $this->markTestSkipped('Only MySQL & Sqlite accept limit/order with UPDATE operation'); $this->sql->update(array('id' => 1))->order('name asc')->limit(1); - $this->assert_sql_has("UPDATE authors SET id=? ORDER BY name asc LIMIT 1", $this->sql->to_s()); + $this->assertSqlHas("UPDATE authors SET id=? ORDER BY name asc LIMIT 1", $this->sql->to_s()); } public function test_update_with_string() { $this->sql->update("name='Bob'"); - $this->assert_sql_has("UPDATE authors SET name='Bob'", $this->sql->to_s()); + $this->assertSqlHas("UPDATE authors SET name='Bob'", $this->sql->to_s()); } public function test_update_with_null() { $this->sql->update(array('id' => 1, 'name' => null))->where('id=1'); - $this->assert_sql_has("UPDATE authors SET id=?, name=? WHERE id=1",$this->sql->to_s()); + $this->assertSqlHas("UPDATE authors SET id=?, name=? WHERE id=1",$this->sql->to_s()); } public function test_delete() { $this->sql->delete(); - $this->assert_equals('DELETE FROM authors',$this->sql->to_s()); + $this->assertEquals('DELETE FROM authors',$this->sql->to_s()); } public function test_delete_with_where() { $this->sql->delete('id=? or name in(?)',1,array('Tito','Mexican')); - $this->assert_equals('DELETE FROM authors WHERE id=? or name in(?,?)',$this->sql->to_s()); - $this->assert_equals(array(1,'Tito','Mexican'),$this->sql->bind_values()); + $this->assertEquals('DELETE FROM authors WHERE id=? or name in(?,?)',$this->sql->to_s()); + $this->assertEquals(array(1,'Tito','Mexican'),$this->sql->bind_values()); } public function test_delete_with_hash() { $this->sql->delete(array('id' => 1, 'name' => array('Tito','Mexican'))); - $this->assert_sql_has("DELETE FROM authors WHERE id=? AND name IN(?,?)",$this->sql->to_s()); - $this->assert_equals(array(1,'Tito','Mexican'),$this->sql->get_where_values()); + $this->assertSqlHas("DELETE FROM authors WHERE id=? AND name IN(?,?)",$this->sql->to_s()); + $this->assertEquals(array(1,'Tito','Mexican'),$this->sql->get_where_values()); } public function test_delete_with_limit_and_order() { if (!$this->conn->accepts_limit_and_order_for_update_and_delete()) - $this->mark_test_skipped('Only MySQL & Sqlite accept limit/order with DELETE operation'); + $this->markTestSkipped('Only MySQL & Sqlite accept limit/order with DELETE operation'); $this->sql->delete(array('id' => 1))->order('name asc')->limit(1); - $this->assert_sql_has("DELETE FROM authors WHERE id=? ORDER BY name asc LIMIT 1",$this->sql->to_s()); + $this->assertSqlHas("DELETE FROM authors WHERE id=? ORDER BY name asc LIMIT 1",$this->sql->to_s()); } public function test_reverse_order() { - $this->assert_equals('id ASC, name DESC', SQLBuilder::reverse_order('id DESC, name ASC')); - $this->assert_equals('id ASC, name DESC , zzz ASC', SQLBuilder::reverse_order('id DESC, name ASC , zzz DESC')); - $this->assert_equals('id DESC, name DESC', SQLBuilder::reverse_order('id, name')); - $this->assert_equals('id DESC', SQLBuilder::reverse_order('id')); - $this->assert_equals('', SQLBuilder::reverse_order('')); - $this->assert_equals(' ', SQLBuilder::reverse_order(' ')); - $this->assert_equals(null, SQLBuilder::reverse_order(null)); + $this->assertEquals('id ASC, name DESC', SQLBuilder::reverse_order('id DESC, name ASC')); + $this->assertEquals('id ASC, name DESC , zzz ASC', SQLBuilder::reverse_order('id DESC, name ASC , zzz DESC')); + $this->assertEquals('id DESC, name DESC', SQLBuilder::reverse_order('id, name')); + $this->assertEquals('id DESC', SQLBuilder::reverse_order('id')); + $this->assertEquals('', SQLBuilder::reverse_order('')); + $this->assertEquals(' ', SQLBuilder::reverse_order(' ')); + $this->assertEquals(null, SQLBuilder::reverse_order(null)); } public function test_create_conditions_from_underscored_string() { - $this->assert_conditions('id=? AND name=? OR z=?',array(1,'Tito','X'),'id_and_name_or_z'); - $this->assert_conditions('id=?',array(1),'id'); - $this->assert_conditions('id IN(?)',array(array(1,2)),'id'); + $this->assertConditions('id=? AND name=? OR z=?',array(1,'Tito','X'),'id_and_name_or_z'); + $this->assertConditions('id=?',array(1),'id'); + $this->assertConditions('id IN(?)',array(array(1,2)),'id'); } public function test_create_conditions_from_underscored_string_with_nulls() { - $this->assert_conditions('id=? AND name IS NULL',array(1,null),'id_and_name'); + $this->assertConditions('id=? AND name IS NULL',array(1,null),'id_and_name'); } public function test_create_conditions_from_underscored_string_with_missing_args() { - $this->assert_conditions('id=? AND name IS NULL OR z IS NULL',array(1,null),'id_and_name_or_z'); - $this->assert_conditions('id IS NULL',null,'id'); + $this->assertConditions('id=? AND name IS NULL OR z IS NULL',array(1,null),'id_and_name_or_z'); + $this->assertConditions('id IS NULL',null,'id'); } public function test_create_conditions_from_underscored_string_with_blank() { - $this->assert_conditions('id=? AND name IS NULL OR z=?',array(1,null,''),'id_and_name_or_z'); + $this->assertConditions('id=? AND name IS NULL OR z=?',array(1,null,''),'id_and_name_or_z'); } public function test_create_conditions_from_underscored_string_invalid() { - $this->assert_equals(null,$this->cond_from_s('')); - $this->assert_equals(null,$this->cond_from_s(null)); + $this->assertEquals(null,$this->cond_from_s('')); + $this->assertEquals(null,$this->cond_from_s(null)); } public function test_create_conditions_from_underscored_string_with_mapped_columns() { - $this->assert_conditions('id=? AND name=?',array(1,'Tito'),'id_and_my_name',array('my_name' => 'name')); + $this->assertConditions('id=? AND name=?',array(1,'Tito'),'id_and_my_name',array('my_name' => 'name')); } public function test_create_hash_from_underscored_string() { $values = array(1,'Tito'); $hash = SQLBuilder::create_hash_from_underscored_string('id_and_my_name',$values); - $this->assert_equals(array('id' => 1, 'my_name' => 'Tito'),$hash); + $this->assertEquals(array('id' => 1, 'my_name' => 'Tito'),$hash); } public function test_create_hash_from_underscored_string_with_mapped_columns() @@ -266,7 +266,7 @@ public function test_create_hash_from_underscored_string_with_mapped_columns() $values = array(1,'Tito'); $map = array('my_name' => 'name'); $hash = SQLBuilder::create_hash_from_underscored_string('id_and_my_name',$values,$map); - $this->assert_equals(array('id' => 1, 'name' => 'Tito'),$hash); + $this->assertEquals(array('id' => 1, 'name' => 'Tito'),$hash); } public function test_where_with_joins_prepends_table_name_to_fields() @@ -276,6 +276,6 @@ public function test_where_with_joins_prepends_table_name_to_fields() $this->sql->joins($joins); $this->sql->where(array('id' => 1, 'name' => 'Tito')); - $this->assert_sql_has("SELECT * FROM authors $joins WHERE authors.id=? AND authors.name=?",(string)$this->sql); + $this->assertSqlHas("SELECT * FROM authors $joins WHERE authors.id=? AND authors.name=?",(string)$this->sql); } } diff --git a/test/SerializationTest.php b/test/SerializationTest.php index 562e24d39..4825e3e8c 100644 --- a/test/SerializationTest.php +++ b/test/SerializationTest.php @@ -5,9 +5,9 @@ class SerializationTest extends DatabaseTest { - public function tear_down() + public function tearDown() { - parent::tear_down(); + parent::tearDown(); ActiveRecord\ArraySerializer::$include_root = false; ActiveRecord\JsonSerializer::$include_root = false; } @@ -23,66 +23,66 @@ public function _a($options=array(), $model=null) public function test_only() { - $this->assert_has_keys('name', 'special', $this->_a(array('only' => array('name', 'special')))); + $this->assertHasKeys('name', 'special', $this->_a(array('only' => array('name', 'special')))); } public function test_only_not_array() { - $this->assert_has_keys('name', $this->_a(array('only' => 'name'))); + $this->assertHasKeys('name', $this->_a(array('only' => 'name'))); } public function test_only_should_only_apply_to_attributes() { - $this->assert_has_keys('name','author', $this->_a(array('only' => 'name', 'include' => 'author'))); - $this->assert_has_keys('book_id','upper_name', $this->_a(array('only' => 'book_id', 'methods' => 'upper_name'))); + $this->assertHasKeys('name','author', $this->_a(array('only' => 'name', 'include' => 'author'))); + $this->assertHasKeys('book_id','upper_name', $this->_a(array('only' => 'book_id', 'methods' => 'upper_name'))); } public function test_only_overrides_except() { - $this->assert_has_keys('name', $this->_a(array('only' => 'name', 'except' => 'name'))); + $this->assertHasKeys('name', $this->_a(array('only' => 'name', 'except' => 'name'))); } public function test_except() { - $this->assert_doesnt_has_keys('name', 'special', $this->_a(array('except' => array('name','special')))); + $this->assertDoesntHasKeys('name', 'special', $this->_a(array('except' => array('name','special')))); } public function test_except_takes_a_string() { - $this->assert_doesnt_has_keys('name', $this->_a(array('except' => 'name'))); + $this->assertDoesntHasKeys('name', $this->_a(array('except' => 'name'))); } public function test_methods() { $a = $this->_a(array('methods' => array('upper_name'))); - $this->assert_equals('ANCIENT ART OF MAIN TANKING', $a['upper_name']); + $this->assertEquals('ANCIENT ART OF MAIN TANKING', $a['upper_name']); } public function test_methods_takes_a_string() { $a = $this->_a(array('methods' => 'upper_name')); - $this->assert_equals('ANCIENT ART OF MAIN TANKING', $a['upper_name']); + $this->assertEquals('ANCIENT ART OF MAIN TANKING', $a['upper_name']); } // methods should take precedence over attributes public function test_methods_method_same_as_attribute() { $a = $this->_a(array('methods' => 'name')); - $this->assert_equals('ancient art of main tanking', $a['name']); + $this->assertEquals('ancient art of main tanking', $a['name']); } public function test_methods_method_alias() { $a = $this->_a(array('methods' => array('name' => 'alias_name'))); - $this->assert_equals('ancient art of main tanking', $a['alias_name']); + $this->assertEquals('ancient art of main tanking', $a['alias_name']); $a = $this->_a(array('methods' => array('upper_name' => 'name'))); - $this->assert_equals('ANCIENT ART OF MAIN TANKING', $a['name']); + $this->assertEquals('ANCIENT ART OF MAIN TANKING', $a['name']); } public function test_include() { $a = $this->_a(array('include' => array('author'))); - $this->assert_has_keys('parent_author_id', $a['author']); + $this->assertHasKeys('parent_author_id', $a['author']); } public function test_include_nested_with_nested_options() @@ -91,29 +91,29 @@ public function test_include_nested_with_nested_options() array('include' => array('events' => array('except' => 'title', 'include' => array('host' => array('only' => 'id'))))), Host::find(4)); - $this->assert_equals(3, count($a['events'])); - $this->assert_doesnt_has_keys('title', $a['events'][0]); - $this->assert_equals(array('id' => 4), $a['events'][0]['host']); + $this->assertEquals(3, count($a['events'])); + $this->assertDoesntHasKeys('title', $a['events'][0]); + $this->assertEquals(array('id' => 4), $a['events'][0]['host']); } public function test_datetime_values_get_converted_to_strings() { $now = new DateTime(); $a = $this->_a(array('only' => 'created_at'),new Author(array('created_at' => $now))); - $this->assert_equals($now->format(ActiveRecord\Serialization::$DATETIME_FORMAT),$a['created_at']); + $this->assertEquals($now->format(ActiveRecord\Serialization::$DATETIME_FORMAT),$a['created_at']); } public function test_to_json() { $book = Book::find(1); $json = $book->to_json(); - $this->assert_equals($book->attributes(),(array)json_decode($json)); + $this->assertEquals($book->attributes(),(array)json_decode($json)); } public function test_to_json_include_root() { ActiveRecord\JsonSerializer::$include_root = true; - $this->assert_not_null(json_decode(Book::find(1)->to_json())->book); + $this->assertNotNull(json_decode(Book::find(1)->to_json())->book); } public function test_to_xml_include() @@ -121,20 +121,20 @@ public function test_to_xml_include() $xml = Host::find(4)->to_xml(array('include' => 'events')); $decoded = get_object_vars(new SimpleXMLElement($xml)); - $this->assert_equals(3, count($decoded['events']->event)); + $this->assertEquals(3, count($decoded['events']->event)); } public function test_to_xml() { $book = Book::find(1); - $this->assert_equals($book->attributes(),get_object_vars(new SimpleXMLElement($book->to_xml()))); + $this->assertEquals($book->attributes(),get_object_vars(new SimpleXMLElement($book->to_xml()))); } public function test_to_array() { $book = Book::find(1); $array = $book->to_array(); - $this->assert_equals($book->attributes(), $array); + $this->assertEquals($book->attributes(), $array); } public function test_to_array_include_root() @@ -143,7 +143,7 @@ public function test_to_array_include_root() $book = Book::find(1); $array = $book->to_array(); $book_attributes = array('book' => $book->attributes()); - $this->assert_equals($book_attributes, $array); + $this->assertEquals($book_attributes, $array); } public function test_to_array_except() @@ -152,37 +152,37 @@ public function test_to_array_except() $array = $book->to_array(array('except' => array('special'))); $book_attributes = $book->attributes(); unset($book_attributes['special']); - $this->assert_equals($book_attributes, $array); + $this->assertEquals($book_attributes, $array); } public function test_works_with_datetime() { Author::find(1)->update_attribute('created_at',new DateTime()); - $this->assert_reg_exp('/[0-9]{4}-[0-9]{2}-[0-9]{2}/',Author::find(1)->to_xml()); - $this->assert_reg_exp('/"updated_at":"[0-9]{4}-[0-9]{2}-[0-9]{2}/',Author::find(1)->to_json()); + $this->assertRegExp('/[0-9]{4}-[0-9]{2}-[0-9]{2}/',Author::find(1)->to_xml()); + $this->assertRegExp('/"updated_at":"[0-9]{4}-[0-9]{2}-[0-9]{2}/',Author::find(1)->to_json()); } public function test_to_xml_skip_instruct() { - $this->assert_same(false,strpos(Book::find(1)->to_xml(array('skip_instruct' => true)),'assert_same(0, strpos(Book::find(1)->to_xml(array('skip_instruct' => false)),'assertSame(false,strpos(Book::find(1)->to_xml(array('skip_instruct' => true)),'assertSame(0, strpos(Book::find(1)->to_xml(array('skip_instruct' => false)),'assert_contains('lasers', Author::first()->to_xml(array('only_method' => 'return_something'))); + $this->assertContains('lasers', Author::first()->to_xml(array('only_method' => 'return_something'))); } public function test_to_csv() { $book = Book::find(1); - $this->assert_equals('1,1,2,"Ancient Art of Main Tanking",0,0',$book->to_csv()); + $this->assertEquals('1,1,2,"Ancient Art of Main Tanking",0,0',$book->to_csv()); } public function test_to_csv_only_header() { $book = Book::find(1); - $this->assert_equals('book_id,author_id,secondary_author_id,name,numeric_test,special', + $this->assertEquals('book_id,author_id,secondary_author_id,name,numeric_test,special', $book->to_csv(array('only_header'=>true)) ); } @@ -190,7 +190,7 @@ public function test_to_csv_only_header() public function test_to_csv_only_method() { $book = Book::find(1); - $this->assert_equals('2,"Ancient Art of Main Tanking"', + $this->assertEquals('2,"Ancient Art of Main Tanking"', $book->to_csv(array('only'=>array('name','secondary_author_id'))) ); } @@ -198,7 +198,7 @@ public function test_to_csv_only_method() public function test_to_csv_only_method_on_header() { $book = Book::find(1); - $this->assert_equals('secondary_author_id,name', + $this->assertEquals('secondary_author_id,name', $book->to_csv(array('only'=>array('secondary_author_id','name'), 'only_header'=>true)) ); @@ -208,7 +208,7 @@ public function test_to_csv_with_custom_delimiter() { $book = Book::find(1); ActiveRecord\CsvSerializer::$delimiter=';'; - $this->assert_equals('1;1;2;"Ancient Art of Main Tanking";0;0',$book->to_csv()); + $this->assertEquals('1;1;2;"Ancient Art of Main Tanking";0;0',$book->to_csv()); } public function test_to_csv_with_custom_enclosure() @@ -216,6 +216,6 @@ public function test_to_csv_with_custom_enclosure() $book = Book::find(1); ActiveRecord\CsvSerializer::$delimiter=','; ActiveRecord\CsvSerializer::$enclosure="'"; - $this->assert_equals("1,1,2,'Ancient Art of Main Tanking',0,0",$book->to_csv()); + $this->assertEquals("1,1,2,'Ancient Art of Main Tanking',0,0",$book->to_csv()); } } diff --git a/test/SqliteAdapterTest.php b/test/SqliteAdapterTest.php index 146152cf8..f272fc5cc 100644 --- a/test/SqliteAdapterTest.php +++ b/test/SqliteAdapterTest.php @@ -3,9 +3,9 @@ class SqliteAdapterTest extends AdapterTest { - public function set_up($connection_name=null) + public function setUp($connection_name=null) { - parent::set_up('sqlite'); + parent::setUp('sqlite'); } public function tearDown() @@ -42,38 +42,38 @@ public function test_limit_with_null_offset_does_not_contain_offset() $sql = 'SELECT * FROM authors ORDER BY name ASC'; $this->conn->query_and_fetch($this->conn->limit($sql,null,1),function($row) use (&$ret) { $ret[] = $row; }); - $this->assert_true(strpos($this->conn->last_query, 'LIMIT 1') !== false); + $this->assertTrue(strpos($this->conn->last_query, 'LIMIT 1') !== false); } public function test_gh183_sqliteadapter_autoincrement() { // defined in lowercase: id integer not null primary key $columns = $this->conn->columns('awesome_people'); - $this->assert_true($columns['id']->auto_increment); + $this->assertTrue($columns['id']->auto_increment); // defined in uppercase: `amenity_id` INTEGER NOT NULL PRIMARY KEY $columns = $this->conn->columns('amenities'); - $this->assert_true($columns['amenity_id']->auto_increment); + $this->assertTrue($columns['amenity_id']->auto_increment); // defined using int: `rm-id` INT NOT NULL $columns = $this->conn->columns('`rm-bldg`'); - $this->assert_false($columns['rm-id']->auto_increment); + $this->assertFalse($columns['rm-id']->auto_increment); // defined using int: id INT NOT NULL PRIMARY KEY $columns = $this->conn->columns('hosts'); - $this->assert_true($columns['id']->auto_increment); + $this->assertTrue($columns['id']->auto_increment); } public function test_datetime_to_string() { $datetime = '2009-01-01 01:01:01'; - $this->assert_equals($datetime,$this->conn->datetime_to_string(date_create($datetime))); + $this->assertEquals($datetime,$this->conn->datetime_to_string(date_create($datetime))); } public function test_date_to_string() { $datetime = '2009-01-01'; - $this->assert_equals($datetime,$this->conn->date_to_string(date_create($datetime))); + $this->assertEquals($datetime,$this->conn->date_to_string(date_create($datetime))); } // not supported diff --git a/test/UtilsTest.php b/test/UtilsTest.php index 37d8bf151..3731d5c51 100644 --- a/test/UtilsTest.php +++ b/test/UtilsTest.php @@ -2,9 +2,9 @@ use ActiveRecord as AR; -class UtilsTest extends SnakeCase_PHPUnit_Framework_TestCase +class UtilsTest extends TestCase { - public function set_up() + public function setUp() { $this->object_array = array(null,null); $this->object_array[0] = new stdClass(); @@ -21,43 +21,43 @@ public function set_up() public function test_collect_with_array_of_objects_using_closure() { - $this->assert_equals(array("0a","1a"),AR\collect($this->object_array,function($obj) { return $obj->a; })); + $this->assertEquals(array("0a","1a"),AR\collect($this->object_array,function($obj) { return $obj->a; })); } public function test_collect_with_array_of_objects_using_string() { - $this->assert_equals(array("0a","1a"),AR\collect($this->object_array,"a")); + $this->assertEquals(array("0a","1a"),AR\collect($this->object_array,"a")); } public function test_collect_with_array_hash_using_closure() { - $this->assert_equals(array("0a","1a"),AR\collect($this->array_hash,function($item) { return $item["a"]; })); + $this->assertEquals(array("0a","1a"),AR\collect($this->array_hash,function($item) { return $item["a"]; })); } public function test_collect_with_array_hash_using_string() { - $this->assert_equals(array("0a","1a"),AR\collect($this->array_hash,"a")); + $this->assertEquals(array("0a","1a"),AR\collect($this->array_hash,"a")); } public function test_array_flatten() { - $this->assert_equals(array(), AR\array_flatten(array())); - $this->assert_equals(array(1), AR\array_flatten(array(1))); - $this->assert_equals(array(1), AR\array_flatten(array(array(1)))); - $this->assert_equals(array(1, 2), AR\array_flatten(array(array(1, 2)))); - $this->assert_equals(array(1, 2), AR\array_flatten(array(array(1), 2))); - $this->assert_equals(array(1, 2), AR\array_flatten(array(1, array(2)))); - $this->assert_equals(array(1, 2, 3), AR\array_flatten(array(1, array(2), 3))); - $this->assert_equals(array(1, 2, 3, 4), AR\array_flatten(array(1, array(2, 3), 4))); - $this->assert_equals(array(1, 2, 3, 4, 5, 6), AR\array_flatten(array(1, array(2, 3), 4, array(5, 6)))); + $this->assertEquals(array(), AR\array_flatten(array())); + $this->assertEquals(array(1), AR\array_flatten(array(1))); + $this->assertEquals(array(1), AR\array_flatten(array(array(1)))); + $this->assertEquals(array(1, 2), AR\array_flatten(array(array(1, 2)))); + $this->assertEquals(array(1, 2), AR\array_flatten(array(array(1), 2))); + $this->assertEquals(array(1, 2), AR\array_flatten(array(1, array(2)))); + $this->assertEquals(array(1, 2, 3), AR\array_flatten(array(1, array(2), 3))); + $this->assertEquals(array(1, 2, 3, 4), AR\array_flatten(array(1, array(2, 3), 4))); + $this->assertEquals(array(1, 2, 3, 4, 5, 6), AR\array_flatten(array(1, array(2, 3), 4, array(5, 6)))); } public function test_all() { - $this->assert_true(AR\all(null,array(null,null))); - $this->assert_true(AR\all(1,array(1,1))); - $this->assert_false(AR\all(1,array(1,'1'))); - $this->assert_false(AR\all(null,array('',null))); + $this->assertTrue(AR\all(null,array(null,null))); + $this->assertTrue(AR\all(1,array(1,1))); + $this->assertFalse(AR\all(1,array(1,'1'))); + $this->assertFalse(AR\all(null,array('',null))); } public function test_classify() @@ -69,7 +69,7 @@ public function test_classify() foreach ($bad_class_names as $s) $class_names[] = AR\classify($s); - $this->assert_equals($class_names, $good_class_names); + $this->assertEquals($class_names, $good_class_names); } public function test_classify_singularize() @@ -81,41 +81,41 @@ public function test_classify_singularize() foreach ($bad_class_names as $s) $class_names[] = AR\classify($s, true); - $this->assert_equals($class_names, $good_class_names); + $this->assertEquals($class_names, $good_class_names); } public function test_singularize() { - $this->assert_equals('order_status',AR\Utils::singularize('order_status')); - $this->assert_equals('order_status',AR\Utils::singularize('order_statuses')); - $this->assert_equals('os_type', AR\Utils::singularize('os_type')); - $this->assert_equals('os_type', AR\Utils::singularize('os_types')); - $this->assert_equals('photo', AR\Utils::singularize('photos')); - $this->assert_equals('pass', AR\Utils::singularize('pass')); - $this->assert_equals('pass', AR\Utils::singularize('passes')); + $this->assertEquals('order_status',AR\Utils::singularize('order_status')); + $this->assertEquals('order_status',AR\Utils::singularize('order_statuses')); + $this->assertEquals('os_type', AR\Utils::singularize('os_type')); + $this->assertEquals('os_type', AR\Utils::singularize('os_types')); + $this->assertEquals('photo', AR\Utils::singularize('photos')); + $this->assertEquals('pass', AR\Utils::singularize('pass')); + $this->assertEquals('pass', AR\Utils::singularize('passes')); } public function test_wrap_strings_in_arrays() { $x = array('1',array('2')); - $this->assert_equals(array(array('1'),array('2')),ActiveRecord\wrap_strings_in_arrays($x)); + $this->assertEquals(array(array('1'),array('2')),ActiveRecord\wrap_strings_in_arrays($x)); $x = '1'; - $this->assert_equals(array(array('1')),ActiveRecord\wrap_strings_in_arrays($x)); + $this->assertEquals(array(array('1')),ActiveRecord\wrap_strings_in_arrays($x)); } public function test_is_hash() { $hash = array('key' => 'value'); - $this->assert_true(ActiveRecord\is_hash($hash)); + $this->assertTrue(ActiveRecord\is_hash($hash)); $notHash = array(0 => 'value'); - $this->assert_false(ActiveRecord\is_hash($notHash)); + $this->assertFalse(ActiveRecord\is_hash($notHash)); } public function test_is_hash_empty_array() { $notHash = array(); - $this->assert_false(ActiveRecord\is_hash($notHash)); + $this->assertFalse(ActiveRecord\is_hash($notHash)); } }; diff --git a/test/ValidatesFormatOfTest.php b/test/ValidatesFormatOfTest.php index 0aaac2f34..a63d3f2ea 100644 --- a/test/ValidatesFormatOfTest.php +++ b/test/ValidatesFormatOfTest.php @@ -10,9 +10,9 @@ class BookFormat extends ActiveRecord\Model class ValidatesFormatOfTest extends DatabaseTest { - public function set_up($connection_name=null) + public function setUp($connection_name=null) { - parent::set_up($connection_name); + parent::setUp($connection_name); BookFormat::$validates_format_of[0] = array('name'); } @@ -21,12 +21,12 @@ public function test_format() BookFormat::$validates_format_of[0]['with'] = '/^[a-z\W]*$/'; $book = new BookFormat(array('author_id' => 1, 'name' => 'testing reg')); $book->save(); - $this->assert_false($book->errors->is_invalid('name')); + $this->assertFalse($book->errors->is_invalid('name')); BookFormat::$validates_format_of[0]['with'] = '/[0-9]/'; $book = new BookFormat(array('author_id' => 1, 'name' => 12)); $book->save(); - $this->assert_false($book->errors->is_invalid('name')); + $this->assertFalse($book->errors->is_invalid('name')); } public function test_invalid_null() @@ -35,7 +35,7 @@ public function test_invalid_null() $book = new BookFormat; $book->name = null; $book->save(); - $this->assert_true($book->errors->is_invalid('name')); + $this->assertTrue($book->errors->is_invalid('name')); } public function test_invalid_blank() @@ -44,7 +44,7 @@ public function test_invalid_blank() $book = new BookFormat; $book->name = ''; $book->save(); - $this->assert_true($book->errors->is_invalid('name')); + $this->assertTrue($book->errors->is_invalid('name')); } public function test_valid_blank_andallow_blank() @@ -53,7 +53,7 @@ public function test_valid_blank_andallow_blank() BookFormat::$validates_format_of[0]['with'] = '/[^0-9]/'; $book = new BookFormat(array('author_id' => 1, 'name' => '')); $book->save(); - $this->assert_false($book->errors->is_invalid('name')); + $this->assertFalse($book->errors->is_invalid('name')); } public function test_valid_null_and_allow_null() @@ -64,7 +64,7 @@ public function test_valid_null_and_allow_null() $book->author_id = 1; $book->name = null; $book->save(); - $this->assert_false($book->errors->is_invalid('name')); + $this->assertFalse($book->errors->is_invalid('name')); } /** @@ -94,7 +94,7 @@ public function test_invalid_with_expression_as_non_regexp() $book = new BookFormat; $book->name = 'blah'; $book->save(); - $this->assert_true($book->errors->is_invalid('name')); + $this->assertTrue($book->errors->is_invalid('name')); } public function test_custom_message() @@ -105,6 +105,6 @@ public function test_custom_message() $book = new BookFormat; $book->name = null; $book->save(); - $this->assert_equals('is using a custom message.', $book->errors->on('name')); + $this->assertEquals('is using a custom message.', $book->errors->on('name')); } } diff --git a/test/ValidatesInclusionAndExclusionOfTest.php b/test/ValidatesInclusionAndExclusionOfTest.php index efa6a28f2..542d9cbd4 100644 --- a/test/ValidatesInclusionAndExclusionOfTest.php +++ b/test/ValidatesInclusionAndExclusionOfTest.php @@ -18,9 +18,9 @@ class BookInclusion extends ActiveRecord\Model class ValidatesInclusionAndExclusionOfTest extends DatabaseTest { - public function set_up($connection_name=null) + public function setUp($connection_name=null) { - parent::set_up($connection_name); + parent::setUp($connection_name); BookInclusion::$validates_inclusion_of[0] = array('name', 'in' => array('blah', 'tanker', 'shark')); BookExclusion::$validates_exclusion_of[0] = array('name', 'in' => array('blah', 'alpha', 'bravo')); } @@ -30,7 +30,7 @@ public function test_inclusion() $book = new BookInclusion; $book->name = 'blah'; $book->save(); - $this->assert_false($book->errors->is_invalid('name')); + $this->assertFalse($book->errors->is_invalid('name')); } public function test_exclusion() @@ -38,7 +38,7 @@ public function test_exclusion() $book = new BookExclusion; $book->name = 'blahh'; $book->save(); - $this->assert_false($book->errors->is_invalid('name')); + $this->assertFalse($book->errors->is_invalid('name')); } public function test_invalid_inclusion() @@ -46,10 +46,10 @@ public function test_invalid_inclusion() $book = new BookInclusion; $book->name = 'thanker'; $book->save(); - $this->assert_true($book->errors->is_invalid('name')); + $this->assertTrue($book->errors->is_invalid('name')); $book->name = 'alpha '; $book->save(); - $this->assert_true($book->errors->is_invalid('name')); + $this->assertTrue($book->errors->is_invalid('name')); } public function test_invalid_exclusion() @@ -57,12 +57,12 @@ public function test_invalid_exclusion() $book = new BookExclusion; $book->name = 'alpha'; $book->save(); - $this->assert_true($book->errors->is_invalid('name')); + $this->assertTrue($book->errors->is_invalid('name')); $book = new BookExclusion; $book->name = 'bravo'; $book->save(); - $this->assert_true($book->errors->is_invalid('name')); + $this->assertTrue($book->errors->is_invalid('name')); } public function test_inclusion_with_numeric() @@ -71,7 +71,7 @@ public function test_inclusion_with_numeric() $book = new BookInclusion; $book->name = 2; $book->save(); - $this->assert_false($book->errors->is_invalid('name')); + $this->assertFalse($book->errors->is_invalid('name')); } public function test_inclusion_with_boolean() @@ -80,7 +80,7 @@ public function test_inclusion_with_boolean() $book = new BookInclusion; $book->name = true; $book->save(); - $this->assert_false($book->errors->is_invalid('name')); + $this->assertFalse($book->errors->is_invalid('name')); } public function test_inclusion_with_null() @@ -89,7 +89,7 @@ public function test_inclusion_with_null() $book = new BookInclusion; $book->name = null; $book->save(); - $this->assert_false($book->errors->is_invalid('name')); + $this->assertFalse($book->errors->is_invalid('name')); } public function test_invalid_inclusion_with_numeric() @@ -98,25 +98,25 @@ public function test_invalid_inclusion_with_numeric() $book = new BookInclusion; $book->name = 5; $book->save(); - $this->assert_true($book->errors->is_invalid('name')); + $this->assertTrue($book->errors->is_invalid('name')); } - public function tes_inclusion_within_option() + public function test_inclusion_within_option() { BookInclusion::$validates_inclusion_of[0] = array('name', 'within' => array('okay')); $book = new BookInclusion; $book->name = 'okay'; $book->save(); - $this->assert_false($book->errors->is_invalid('name')); + $this->assertFalse($book->errors->is_invalid('name')); } - public function tes_inclusion_scalar_value() + public function test_inclusion_scalar_value() { BookInclusion::$validates_inclusion_of[0] = array('name', 'within' => 'okay'); $book = new BookInclusion; $book->name = 'okay'; $book->save(); - $this->assert_false($book->errors->is_invalid('name')); + $this->assertFalse($book->errors->is_invalid('name')); } public function test_valid_null() @@ -125,7 +125,7 @@ public function test_valid_null() $book = new BookInclusion; $book->name = null; $book->save(); - $this->assert_false($book->errors->is_invalid('name')); + $this->assertFalse($book->errors->is_invalid('name')); } public function test_valid_blank() @@ -134,7 +134,7 @@ public function test_valid_blank() $book = new BookInclusion; $book->name = ''; $book->save(); - $this->assert_false($book->errors->is_invalid('name')); + $this->assertFalse($book->errors->is_invalid('name')); } public function test_custom_message() @@ -146,11 +146,11 @@ public function test_custom_message() $book = new BookInclusion; $book->name = 'not included'; $book->save(); - $this->assert_equals('is using a custom message.', $book->errors->on('name')); + $this->assertEquals('is using a custom message.', $book->errors->on('name')); $book = new BookExclusion; $book->name = 'bravo'; $book->save(); - $this->assert_equals('is using a custom message.', $book->errors->on('name')); + $this->assertEquals('is using a custom message.', $book->errors->on('name')); } } diff --git a/test/ValidatesLengthOfTest.php b/test/ValidatesLengthOfTest.php index 99ebe786c..74787e73f 100644 --- a/test/ValidatesLengthOfTest.php +++ b/test/ValidatesLengthOfTest.php @@ -14,9 +14,9 @@ class BookSize extends ActiveRecord\Model class ValidatesLengthOfTest extends DatabaseTest { - public function set_up($connection_name=null) + public function setUp($connection_name=null) { - parent::set_up($connection_name); + parent::setUp($connection_name); BookLength::$validates_length_of[0] = array('name', 'allow_blank' => false, 'allow_null' => false); } @@ -26,7 +26,7 @@ public function test_within() $book = new BookLength; $book->name = '12345'; $book->save(); - $this->assert_false($book->errors->is_invalid('name')); + $this->assertFalse($book->errors->is_invalid('name')); } public function test_within_error_message() @@ -35,11 +35,11 @@ public function test_within_error_message() $book = new BookLength(); $book->name = '1'; $book->is_valid(); - $this->assert_equals(array('Name is too short (minimum is 2 characters)'),$book->errors->full_messages()); + $this->assertEquals(array('Name is too short (minimum is 2 characters)'),$book->errors->full_messages()); $book->name = '123456'; $book->is_valid(); - $this->assert_equals(array('Name is too long (maximum is 5 characters)'),$book->errors->full_messages()); + $this->assertEquals(array('Name is too long (maximum is 5 characters)'),$book->errors->full_messages()); } public function test_within_custom_error_message() @@ -50,11 +50,11 @@ public function test_within_custom_error_message() $book = new BookLength(); $book->name = '1'; $book->is_valid(); - $this->assert_equals(array('Name is not between 2 and 5 characters'),$book->errors->full_messages()); + $this->assertEquals(array('Name is not between 2 and 5 characters'),$book->errors->full_messages()); $book->name = '123456'; $book->is_valid(); - $this->assert_equals(array('Name is not between 2 and 5 characters'),$book->errors->full_messages()); + $this->assertEquals(array('Name is not between 2 and 5 characters'),$book->errors->full_messages()); } public function test_valid_in() @@ -63,7 +63,7 @@ public function test_valid_in() $book = new BookLength; $book->name = '12345'; $book->save(); - $this->assert_false($book->errors->is_invalid('name')); + $this->assertFalse($book->errors->is_invalid('name')); } public function test_aliased_size_of() @@ -73,7 +73,7 @@ public function test_aliased_size_of() $book = new BookSize; $book->name = '12345'; $book->save(); - $this->assert_false($book->errors->is_invalid('name')); + $this->assertFalse($book->errors->is_invalid('name')); } public function test_invalid_within_and_in() @@ -82,14 +82,14 @@ public function test_invalid_within_and_in() $book = new BookLength; $book->name = 'four'; $book->save(); - $this->assert_true($book->errors->is_invalid('name')); + $this->assertTrue($book->errors->is_invalid('name')); - $this->set_up(); + $this->setUp(); BookLength::$validates_length_of[0]['in'] = array(1, 3); $book = new BookLength; $book->name = 'four'; $book->save(); - $this->assert_true($book->errors->is_invalid('name')); + $this->assertTrue($book->errors->is_invalid('name')); } public function test_valid_null() @@ -100,7 +100,7 @@ public function test_valid_null() $book = new BookLength; $book->name = null; $book->save(); - $this->assert_false($book->errors->is_invalid('name')); + $this->assertFalse($book->errors->is_invalid('name')); } public function test_valid_blank() @@ -111,7 +111,7 @@ public function test_valid_blank() $book = new BookLength; $book->name = ''; $book->save(); - $this->assert_false($book->errors->is_invalid('name')); + $this->assertFalse($book->errors->is_invalid('name')); } public function test_invalid_blank() @@ -121,8 +121,8 @@ public function test_invalid_blank() $book = new BookLength; $book->name = ''; $book->save(); - $this->assert_true($book->errors->is_invalid('name')); - $this->assert_equals('is too short (minimum is 1 characters)', $book->errors->on('name')); + $this->assertTrue($book->errors->is_invalid('name')); + $this->assertEquals('is too short (minimum is 1 characters)', $book->errors->on('name')); } public function test_invalid_null_within() @@ -132,8 +132,8 @@ public function test_invalid_null_within() $book = new BookLength; $book->name = null; $book->save(); - $this->assert_true($book->errors->is_invalid('name')); - $this->assert_equals('is too short (minimum is 1 characters)', $book->errors->on('name')); + $this->assertTrue($book->errors->is_invalid('name')); + $this->assertEquals('is too short (minimum is 1 characters)', $book->errors->on('name')); } public function test_invalid_null_minimum() @@ -143,8 +143,8 @@ public function test_invalid_null_minimum() $book = new BookLength; $book->name = null; $book->save(); - $this->assert_true($book->errors->is_invalid('name')); - $this->assert_equals('is too short (minimum is 1 characters)', $book->errors->on('name')); + $this->assertTrue($book->errors->is_invalid('name')); + $this->assertEquals('is too short (minimum is 1 characters)', $book->errors->on('name')); } @@ -155,7 +155,7 @@ public function test_valid_null_maximum() $book = new BookLength; $book->name = null; $book->save(); - $this->assert_false($book->errors->is_invalid('name')); + $this->assertFalse($book->errors->is_invalid('name')); } public function test_float_as_impossible_range_option() @@ -166,17 +166,17 @@ public function test_float_as_impossible_range_option() try { $book->save(); } catch (ActiveRecord\ValidationsArgumentError $e) { - $this->assert_equals('maximum value cannot use a float for length.', $e->getMessage()); + $this->assertEquals('maximum value cannot use a float for length.', $e->getMessage()); } - $this->set_up(); + $this->setUp(); BookLength::$validates_length_of[0]['is'] = 1.8; $book = new BookLength; $book->name = '123'; try { $book->save(); } catch (ActiveRecord\ValidationsArgumentError $e) { - $this->assert_equals('is value cannot use a float for length.', $e->getMessage()); + $this->assertEquals('is value cannot use a float for length.', $e->getMessage()); return; } @@ -192,7 +192,7 @@ public function test_signed_integer_as_impossible_within_option() try { $book->save(); } catch (ActiveRecord\ValidationsArgumentError $e) { - $this->assert_equals('minimum value cannot use a signed integer.', $e->getMessage()); + $this->assertEquals('minimum value cannot use a signed integer.', $e->getMessage()); return; } @@ -208,7 +208,7 @@ public function test_signed_integer_as_impossible_is_option() try { $book->save(); } catch (ActiveRecord\ValidationsArgumentError $e) { - $this->assert_equals('is value cannot use a signed integer.', $e->getMessage()); + $this->assertEquals('is value cannot use a signed integer.', $e->getMessage()); return; } @@ -222,7 +222,7 @@ public function test_lack_of_option() $book->name = null; $book->save(); } catch (ActiveRecord\ValidationsArgumentError $e) { - $this->assert_equals('Range unspecified. Specify the [within], [maximum], or [is] option.', $e->getMessage()); + $this->assertEquals('Range unspecified. Specify the [within], [maximum], or [is] option.', $e->getMessage()); return; } @@ -239,7 +239,7 @@ public function test_too_many_options() $book->name = null; $book->save(); } catch (ActiveRecord\ValidationsArgumentError $e) { - $this->assert_equals('Too many range options specified. Choose only one.', $e->getMessage()); + $this->assertEquals('Too many range options specified. Choose only one.', $e->getMessage()); return; } @@ -256,7 +256,7 @@ public function test_too_many_options_with_different_option_types() $book->name = null; $book->save(); } catch (ActiveRecord\ValidationsArgumentError $e) { - $this->assert_equals('Too many range options specified. Choose only one.', $e->getMessage()); + $this->assertEquals('Too many range options specified. Choose only one.', $e->getMessage()); return; } @@ -292,7 +292,7 @@ public function test_validates_length_of_maximum() BookLength::$validates_length_of[0] = array('name', 'maximum' => 10); $book = new BookLength(array('name' => '12345678901')); $book->is_valid(); - $this->assert_equals(array("Name is too long (maximum is 10 characters)"),$book->errors->full_messages()); + $this->assertEquals(array("Name is too long (maximum is 10 characters)"),$book->errors->full_messages()); } public function test_validates_length_of_minimum() @@ -300,7 +300,7 @@ public function test_validates_length_of_minimum() BookLength::$validates_length_of[0] = array('name', 'minimum' => 2); $book = new BookLength(array('name' => '1')); $book->is_valid(); - $this->assert_equals(array("Name is too short (minimum is 2 characters)"),$book->errors->full_messages()); + $this->assertEquals(array("Name is too short (minimum is 2 characters)"),$book->errors->full_messages()); } public function test_validates_length_of_min_max_custom_message() @@ -308,12 +308,12 @@ public function test_validates_length_of_min_max_custom_message() BookLength::$validates_length_of[0] = array('name', 'maximum' => 10, 'message' => 'is far too long'); $book = new BookLength(array('name' => '12345678901')); $book->is_valid(); - $this->assert_equals(array("Name is far too long"),$book->errors->full_messages()); + $this->assertEquals(array("Name is far too long"),$book->errors->full_messages()); BookLength::$validates_length_of[0] = array('name', 'minimum' => 10, 'message' => 'is far too short'); $book = new BookLength(array('name' => '123456789')); $book->is_valid(); - $this->assert_equals(array("Name is far too short"),$book->errors->full_messages()); + $this->assertEquals(array("Name is far too short"),$book->errors->full_messages()); } public function test_validates_length_of_min_max_custom_message_overridden() @@ -321,7 +321,7 @@ public function test_validates_length_of_min_max_custom_message_overridden() BookLength::$validates_length_of[0] = array('name', 'minimum' => 10, 'too_short' => 'is too short', 'message' => 'is custom message'); $book = new BookLength(array('name' => '123456789')); $book->is_valid(); - $this->assert_equals(array("Name is custom message"),$book->errors->full_messages()); + $this->assertEquals(array("Name is custom message"),$book->errors->full_messages()); } public function test_validates_length_of_is() @@ -329,6 +329,6 @@ public function test_validates_length_of_is() BookLength::$validates_length_of[0] = array('name', 'is' => 2); $book = new BookLength(array('name' => '123')); $book->is_valid(); - $this->assert_equals(array("Name is the wrong length (should be 2 characters)"),$book->errors->full_messages()); + $this->assertEquals(array("Name is the wrong length (should be 2 characters)"),$book->errors->full_messages()); } } diff --git a/test/ValidatesNumericalityOfTest.php b/test/ValidatesNumericalityOfTest.php index ac9d6e2e3..bb5e4081a 100644 --- a/test/ValidatesNumericalityOfTest.php +++ b/test/ValidatesNumericalityOfTest.php @@ -19,86 +19,86 @@ class ValidatesNumericalityOfTest extends DatabaseTest static $INTEGERS = array(0, 10, -10); static $JUNK = array("not a number", "42 not a number", "00-1", "--3", "+-3", "+3-1", "-+019.0", "12.12.13.12", "123\nnot a number"); - public function set_up($connection_name=null) + public function setUp($connection_name=null) { - parent::set_up($connection_name); + parent::setUp($connection_name); BookNumericality::$validates_numericality_of = array( array('numeric_test') ); } - private function assert_validity($value, $boolean, $msg=null) + private function assertValidity($value, $boolean, $msg=null) { $book = new BookNumericality; $book->numeric_test = $value; if ($boolean == 'valid') { - $this->assert_true($book->save()); - $this->assert_false($book->errors->is_invalid('numeric_test')); + $this->assertTrue($book->save()); + $this->assertFalse($book->errors->is_invalid('numeric_test')); } else { - $this->assert_false($book->save()); - $this->assert_true($book->errors->is_invalid('numeric_test')); + $this->assertFalse($book->save()); + $this->assertTrue($book->errors->is_invalid('numeric_test')); if (!is_null($msg)) - $this->assert_same($msg, $book->errors->on('numeric_test')); + $this->assertSame($msg, $book->errors->on('numeric_test')); } } - private function assert_invalid($values, $msg=null) + private function assertInvalid($values, $msg=null) { foreach ($values as $value) - $this->assert_validity($value, 'invalid', $msg); + $this->assertValidity($value, 'invalid', $msg); } - private function assert_valid($values, $msg=null) + private function assertValid($values, $msg=null) { foreach ($values as $value) - $this->assert_validity($value, 'valid', $msg); + $this->assertValidity($value, 'valid', $msg); } public function test_numericality() { - //$this->assert_invalid(array("0xdeadbeef")); + //$this->assertInvalid(array("0xdeadbeef")); - $this->assert_valid(array_merge(self::$FLOATS, self::$INTEGERS)); - $this->assert_invalid(array_merge(self::$NULL, self::$BLANK, self::$JUNK)); + $this->assertValid(array_merge(self::$FLOATS, self::$INTEGERS)); + $this->assertInvalid(array_merge(self::$NULL, self::$BLANK, self::$JUNK)); } public function test_not_anumber() { - $this->assert_invalid(array('blah'), 'is not a number'); + $this->assertInvalid(array('blah'), 'is not a number'); } public function test_invalid_null() { - $this->assert_invalid(array(null)); + $this->assertInvalid(array(null)); } public function test_invalid_blank() { - $this->assert_invalid(array(' ', ' '), 'is not a number'); + $this->assertInvalid(array(' ', ' '), 'is not a number'); } public function test_invalid_whitespace() { - $this->assert_invalid(array('')); + $this->assertInvalid(array('')); } public function test_valid_null() { BookNumericality::$validates_numericality_of[0]['allow_null'] = true; - $this->assert_valid(array(null)); + $this->assertValid(array(null)); } public function test_only_integer() { BookNumericality::$validates_numericality_of[0]['only_integer'] = true; - $this->assert_valid(array(1, '1')); - $this->assert_invalid(array(1.5, '1.5')); + $this->assertValid(array(1, '1')); + $this->assertInvalid(array(1.5, '1.5')); } public function test_only_integer_matching_does_not_ignore_other_options() @@ -106,47 +106,47 @@ public function test_only_integer_matching_does_not_ignore_other_options() BookNumericality::$validates_numericality_of[0]['only_integer'] = true; BookNumericality::$validates_numericality_of[0]['greater_than'] = 0; - $this->assert_invalid(array(-1,'-1')); + $this->assertInvalid(array(-1,'-1')); } public function test_greater_than() { BookNumericality::$validates_numericality_of[0]['greater_than'] = 5; - $this->assert_valid(array(6, '7')); - $this->assert_invalid(array(5, '5'), 'must be greater than 5'); + $this->assertValid(array(6, '7')); + $this->assertInvalid(array(5, '5'), 'must be greater than 5'); } public function test_greater_than_or_equal_to() { BookNumericality::$validates_numericality_of[0]['greater_than_or_equal_to'] = 5; - $this->assert_valid(array(5, 5.1, '5.1')); - $this->assert_invalid(array(-50, 4.9, '4.9','-5.1')); + $this->assertValid(array(5, 5.1, '5.1')); + $this->assertInvalid(array(-50, 4.9, '4.9','-5.1')); } public function test_less_than() { BookNumericality::$validates_numericality_of[0]['less_than'] = 5; - $this->assert_valid(array(4.9, -1, 0, '-5')); - $this->assert_invalid(array(5, '5'), 'must be less than 5'); + $this->assertValid(array(4.9, -1, 0, '-5')); + $this->assertInvalid(array(5, '5'), 'must be less than 5'); } public function test_less_than_or_equal_to() { BookNumericality::$validates_numericality_of[0]['less_than_or_equal_to'] = 5; - $this->assert_valid(array(5, -1, 0, 4.9, '-5')); - $this->assert_invalid(array('8', 5.1), 'must be less than or equal to 5'); + $this->assertValid(array(5, -1, 0, 4.9, '-5')); + $this->assertInvalid(array('8', 5.1), 'must be less than or equal to 5'); } public function test_greater_than_less_than_and_even() { BookNumericality::$validates_numericality_of[0] = array('numeric_test', 'greater_than' => 1, 'less_than' => 4, 'even' => true); - $this->assert_valid(array(2)); - $this->assert_invalid(array(1,3,4)); + $this->assertValid(array(2)); + $this->assertInvalid(array(1,3,4)); } public function test_custom_message() @@ -156,7 +156,7 @@ public function test_custom_message() ); $book = new BookNumericality(array('numeric_test' => 'NaN')); $book->is_valid(); - $this->assert_equals(array('Numeric test Hello'),$book->errors->full_messages()); + $this->assertEquals(array('Numeric test Hello'),$book->errors->full_messages()); } } diff --git a/test/ValidatesOnSaveCreateUpdateTest.php b/test/ValidatesOnSaveCreateUpdateTest.php index 70f7a9c25..02eef1488 100644 --- a/test/ValidatesOnSaveCreateUpdateTest.php +++ b/test/ValidatesOnSaveCreateUpdateTest.php @@ -13,61 +13,61 @@ public function test_validations_only_run_on_create() { BookOn::$validates_presence_of[0] = array('name', 'on' => 'create'); $book = new BookOn(); - $this->assert_false($book->is_valid()); + $this->assertFalse($book->is_valid()); $book->secondary_author_id = 1; - $this->assert_false( $book->save() ); + $this->assertFalse( $book->save() ); $book->name = 'Baz'; - $this->assert_true( $book->save() ); + $this->assertTrue( $book->save() ); $book->name = null; - $this->assert_true( $book->save() ); + $this->assertTrue( $book->save() ); } public function test_validations_only_run_on_update() { BookOn::$validates_presence_of[0] = array('name', 'on' => 'update'); $book = new BookOn(); - $this->assert_true($book->save()); + $this->assertTrue($book->save()); $book->name = null; - $this->assert_false( $book->save() ); + $this->assertFalse( $book->save() ); $book->name = 'Baz'; - $this->assert_true( $book->save() ); + $this->assertTrue( $book->save() ); } public function test_validations_only_run_on_save() { BookOn::$validates_presence_of[0] = array('name', 'on' => 'save'); $book = new BookOn(); - $this->assert_false($book->is_valid()); + $this->assertFalse($book->is_valid()); $book->secondary_author_id = 1; - $this->assert_false( $book->save() ); + $this->assertFalse( $book->save() ); $book->name = 'Baz'; - $this->assert_true( $book->save() ); + $this->assertTrue( $book->save() ); $book->name = null; - $this->assert_false( $book->save() ); + $this->assertFalse( $book->save() ); } public function test_validations_run_always_without_on() { BookOn::$validates_presence_of[0] = array('name'); $book = new BookOn(); - $this->assert_false($book->is_valid()); + $this->assertFalse($book->is_valid()); $book->secondary_author_id = 1; - $this->assert_false( $book->save() ); + $this->assertFalse( $book->save() ); $book->name = 'Baz'; - $this->assert_true( $book->save() ); + $this->assertTrue( $book->save() ); $book->name = null; - $this->assert_false( $book->save() ); + $this->assertFalse( $book->save() ); } } \ No newline at end of file diff --git a/test/ValidatesPresenceOfTest.php b/test/ValidatesPresenceOfTest.php index 16c2354de..bfbcdd11e 100644 --- a/test/ValidatesPresenceOfTest.php +++ b/test/ValidatesPresenceOfTest.php @@ -23,37 +23,37 @@ class ValidatesPresenceOfTest extends DatabaseTest public function test_presence() { $book = new BookPresence(array('name' => 'blah')); - $this->assert_false($book->is_invalid()); + $this->assertFalse($book->is_invalid()); } public function test_presence_on_date_field_is_valid() { $author = new AuthorPresence(array('some_date' => '2010-01-01')); - $this->assert_true($author->is_valid()); + $this->assertTrue($author->is_valid()); } public function test_presence_on_date_field_is_not_valid() { $author = new AuthorPresence(); - $this->assert_false($author->is_valid()); + $this->assertFalse($author->is_valid()); } public function test_invalid_null() { $book = new BookPresence(array('name' => null)); - $this->assert_true($book->is_invalid()); + $this->assertTrue($book->is_invalid()); } public function test_invalid_blank() { $book = new BookPresence(array('name' => '')); - $this->assert_true($book->is_invalid()); + $this->assertTrue($book->is_invalid()); } public function test_valid_white_space() { $book = new BookPresence(array('name' => ' ')); - $this->assert_false($book->is_invalid()); + $this->assertFalse($book->is_invalid()); } public function test_custom_message() @@ -62,12 +62,12 @@ public function test_custom_message() $book = new BookPresence(array('name' => null)); $book->is_valid(); - $this->assert_equals('is using a custom message.', $book->errors->on('name')); + $this->assertEquals('is using a custom message.', $book->errors->on('name')); } public function test_valid_zero() { $book = new BookPresence(array('name' => 0)); - $this->assert_true($book->is_valid()); + $this->assertTrue($book->is_valid()); } } diff --git a/test/ValidationsTest.php b/test/ValidationsTest.php index d34f9e07c..fc16df8aa 100644 --- a/test/ValidationsTest.php +++ b/test/ValidationsTest.php @@ -53,9 +53,9 @@ class ValuestoreValidations extends ActiveRecord\Model class ValidationsTest extends DatabaseTest { - public function set_up($connection_name=null) + public function setUp($connection_name=null) { - parent::set_up($connection_name); + parent::setUp($connection_name); BookValidations::$validates_presence_of[0] = 'name'; BookValidations::$validates_uniqueness_of[0] = 'name'; @@ -66,33 +66,33 @@ public function set_up($connection_name=null) public function test_is_valid_invokes_validations() { $book = new Book; - $this->assert_true(empty($book->errors)); + $this->assertTrue(empty($book->errors)); $book->is_valid(); - $this->assert_false(empty($book->errors)); + $this->assertFalse(empty($book->errors)); } public function test_is_valid_returns_true_if_no_validations_exist() { $book = new Book; - $this->assert_true($book->is_valid()); + $this->assertTrue($book->is_valid()); } public function test_is_valid_returns_false_if_failed_validations() { $book = new BookValidations; - $this->assert_false($book->is_valid()); + $this->assertFalse($book->is_valid()); } public function test_is_invalid() { $book = new Book(); - $this->assert_false($book->is_invalid()); + $this->assertFalse($book->is_invalid()); } public function test_is_invalid_is_true() { $book = new BookValidations(); - $this->assert_true($book->is_invalid()); + $this->assertTrue($book->is_invalid()); } public function test_is_valid_does_not_revalidate() @@ -110,8 +110,8 @@ public function test_is_valid_does_not_revalidate() * rehashed, becoming different from `password` and then the result * would be different from precedent (and also a bug). */ - $this->assert_true($user->is_valid()); - $this->assert_equals(!$user->is_valid(), $user->is_invalid()); + $this->assertTrue($user->is_valid()); + $this->assertEquals(!$user->is_valid(), $user->is_invalid()); } public function test_is_valid_will_revalidate_if_attribute_changes() @@ -122,13 +122,13 @@ public function test_is_valid_will_revalidate_if_attribute_changes() ); $user = new UserValidations($attrs); - $this->assert_false($user->is_valid()); + $this->assertFalse($user->is_valid()); $user->password = 'secret'; // because custom validation is coded bad (on purpose), we have to // reset password_confirm $user->password_confirm = 'secret'; - $this->assert_true($user->is_valid()); + $this->assertTrue($user->is_valid()); } public function test_is_invalid_will_revalidate_if_attribute_changes() @@ -139,13 +139,13 @@ public function test_is_invalid_will_revalidate_if_attribute_changes() ); $user = new UserValidations($attrs); - $this->assert_true($user->is_invalid()); + $this->assertTrue($user->is_invalid()); $user->password = 'secret'; // because custom validation is coded bad (on purpose), we have to // reset password_confirm $user->password_confirm = 'secret'; - $this->assert_false($user->is_invalid()); + $this->assertFalse($user->is_invalid()); } public function test_is_valid_must_be_forced_if_a_virtual_attribute_changes() @@ -156,15 +156,15 @@ public function test_is_valid_must_be_forced_if_a_virtual_attribute_changes() ); $user = new UserValidations($attrs); - $this->assert_false($user->is_valid()); + $this->assertFalse($user->is_valid()); $user->password_confirm = 'secret'; // Actually we check only attribute set by `__set` magic method. - $this->assert_false($user->is_valid()); + $this->assertFalse($user->is_valid()); // Passing `true` will force the validation of `user`, giving the // right result. - $this->assert_true($user->is_valid(true)); + $this->assertTrue($user->is_valid(true)); } public function test_is_iterable() @@ -173,7 +173,7 @@ public function test_is_iterable() $book->is_valid(); foreach ($book->errors as $name => $message) - $this->assert_equals("Name can't be blank",$message); + $this->assertEquals("Name can't be blank",$message); } public function test_full_messages() @@ -181,7 +181,7 @@ public function test_full_messages() $book = new BookValidations(); $book->is_valid(); - $this->assert_equals(array("Name can't be blank"),array_values($book->errors->full_messages(array('hash' => true)))); + $this->assertEquals(array("Name can't be blank"),array_values($book->errors->full_messages(array('hash' => true)))); } public function test_to_array() @@ -189,7 +189,7 @@ public function test_to_array() $book = new BookValidations(); $book->is_valid(); - $this->assert_equals(array("name" => array("Name can't be blank")), $book->errors->to_array()); + $this->assertEquals(array("name" => array("Name can't be blank")), $book->errors->to_array()); } public function test_toString() @@ -198,7 +198,7 @@ public function test_toString() $book->is_valid(); $book->errors->add('secondary_author_id', "is invalid"); - $this->assert_equals("Name can't be blank\nSecondary author id is invalid", (string) $book->errors); + $this->assertEquals("Name can't be blank\nSecondary author id is invalid", (string) $book->errors); } public function test_validates_uniqueness_of() @@ -206,14 +206,14 @@ public function test_validates_uniqueness_of() BookValidations::create(array('name' => 'bob')); $book = BookValidations::create(array('name' => 'bob')); - $this->assert_equals(array("Name must be unique"),$book->errors->full_messages()); - $this->assert_equals(1,BookValidations::count(array('conditions' => "name='bob'"))); + $this->assertEquals(array("Name must be unique"),$book->errors->full_messages()); + $this->assertEquals(1,BookValidations::count(array('conditions' => "name='bob'"))); } public function test_validates_uniqueness_of_excludes_self() { $book = BookValidations::first(); - $this->assert_equals(true,$book->is_valid()); + $this->assertEquals(true,$book->is_valid()); } public function test_validates_uniqueness_of_with_multiple_fields() @@ -221,7 +221,7 @@ public function test_validates_uniqueness_of_with_multiple_fields() BookValidations::$validates_uniqueness_of[0] = array(array('name','special')); $book1 = BookValidations::first(); $book2 = new BookValidations(array('name' => $book1->name, 'special' => $book1->special+1)); - $this->assert_true($book2->is_valid()); + $this->assertTrue($book2->is_valid()); } public function test_validates_uniqueness_of_with_multiple_fields_is_not_unique() @@ -229,16 +229,16 @@ public function test_validates_uniqueness_of_with_multiple_fields_is_not_unique( BookValidations::$validates_uniqueness_of[0] = array(array('name','special')); $book1 = BookValidations::first(); $book2 = new BookValidations(array('name' => $book1->name, 'special' => $book1->special)); - $this->assert_false($book2->is_valid()); - $this->assert_equals(array('Name and special must be unique'),$book2->errors->full_messages()); + $this->assertFalse($book2->is_valid()); + $this->assertEquals(array('Name and special must be unique'),$book2->errors->full_messages()); } public function test_validates_uniqueness_of_works_with_alias_attribute() { BookValidations::$validates_uniqueness_of[0] = array(array('name_alias','x')); $book = BookValidations::create(array('name_alias' => 'Another Book', 'x' => 2)); - $this->assert_false($book->is_valid()); - $this->assert_equals(array('Name alias and x must be unique'), $book->errors->full_messages()); + $this->assertFalse($book->is_valid()); + $this->assertEquals(array('Name alias and x must be unique'), $book->errors->full_messages()); } public function test_validates_uniqueness_of_works_with_mysql_reserved_word_as_column_name() @@ -246,36 +246,36 @@ public function test_validates_uniqueness_of_works_with_mysql_reserved_word_as_c ValuestoreValidations::create(array('key' => 'GA_KEY', 'value' => 'UA-1234567-1')); $valuestore = ValuestoreValidations::create(array('key' => 'GA_KEY', 'value' => 'UA-1234567-2')); - $this->assert_equals(array("Key must be unique"),$valuestore->errors->full_messages()); - $this->assert_equals(1,ValuestoreValidations::count(array('conditions' => "`key`='GA_KEY'"))); + $this->assertEquals(array("Key must be unique"),$valuestore->errors->full_messages()); + $this->assertEquals(1,ValuestoreValidations::count(array('conditions' => "`key`='GA_KEY'"))); } public function test_get_validation_rules() { $validators = BookValidations::first()->get_validation_rules(); - $this->assert_true(in_array(array('validator' => 'validates_presence_of'),$validators['name'])); + $this->assertTrue(in_array(array('validator' => 'validates_presence_of'),$validators['name'])); } public function test_model_is_nulled_out_to_prevent_memory_leak() { $book = new BookValidations(); $book->is_valid(); - $this->assert_true(strpos(serialize($book->errors),'model";N;') !== false); + $this->assertTrue(strpos(serialize($book->errors),'model";N;') !== false); } public function test_validations_takes_strings() { BookValidations::$validates_presence_of = array('numeric_test', array('special'), 'name'); $book = new BookValidations(array('numeric_test' => 1, 'special' => 1)); - $this->assert_false($book->is_valid()); + $this->assertFalse($book->is_valid()); } public function test_gh131_custom_validation() { $book = new BookValidations(array('name' => 'test_custom_validation')); $book->save(); - $this->assert_true($book->errors->is_invalid('name')); - $this->assert_equals(BookValidations::$custom_validator_error_msg, $book->errors->on('name')); + $this->assertTrue($book->errors->is_invalid('name')); + $this->assertEquals(BookValidations::$custom_validator_error_msg, $book->errors->on('name')); } } diff --git a/test/helpers/AdapterTest.php b/test/helpers/AdapterTest.php index b4a156c26..232087afa 100644 --- a/test/helpers/AdapterTest.php +++ b/test/helpers/AdapterTest.php @@ -5,13 +5,13 @@ class AdapterTest extends DatabaseTest { const InvalidDb = '__1337__invalid_db__'; - public function set_up($connection_name=null) + public function setUp($connection_name=null) { if (($connection_name && !in_array($connection_name, PDO::getAvailableDrivers())) || ActiveRecord\Config::instance()->get_connection_info($connection_name) == 'skip') - $this->mark_test_skipped($connection_name . ' drivers are not present'); + $this->markTestSkipped($connection_name . ' drivers are not present'); - parent::set_up($connection_name); + parent::setUp($connection_name); } public function test_i_has_a_default_port_unless_im_sqlite() @@ -20,19 +20,19 @@ public function test_i_has_a_default_port_unless_im_sqlite() return; $c = $this->conn; - $this->assert_true($c::$DEFAULT_PORT > 0); + $this->assertTrue($c::$DEFAULT_PORT > 0); } public function test_should_set_adapter_variables() { - $this->assert_not_null($this->conn->adapter); + $this->assertNotNull($this->conn->adapter); } public function test_null_connection_string_uses_default_connection() { - $this->assert_not_null(ActiveRecord\Connection::instance(null)); - $this->assert_not_null(ActiveRecord\Connection::instance('')); - $this->assert_not_null(ActiveRecord\Connection::instance()); + $this->assertNotNull(ActiveRecord\Connection::instance(null)); + $this->assertNotNull(ActiveRecord\Connection::instance('')); + $this->assertNotNull(ActiveRecord\Connection::instance()); } /** @@ -117,37 +117,37 @@ public function test_connect_to_invalid_database() public function test_date_time_type() { $columns = $this->conn->columns('authors'); - $this->assert_equals('datetime',$columns['created_at']->raw_type); - $this->assert_equals(Column::DATETIME,$columns['created_at']->type); - $this->assert_true($columns['created_at']->length > 0); + $this->assertEquals('datetime',$columns['created_at']->raw_type); + $this->assertEquals(Column::DATETIME,$columns['created_at']->type); + $this->assertTrue($columns['created_at']->length > 0); } public function test_date() { $columns = $this->conn->columns('authors'); - $this->assert_equals('date', $columns['some_Date']->raw_type); - $this->assert_equals(Column::DATE, $columns['some_Date']->type); - $this->assert_true($columns['some_Date']->length >= 7); + $this->assertEquals('date', $columns['some_Date']->raw_type); + $this->assertEquals(Column::DATE, $columns['some_Date']->type); + $this->assertTrue($columns['some_Date']->length >= 7); } public function test_columns_no_inflection_on_hash_key() { $author_columns = $this->conn->columns('authors'); - $this->assert_true(array_key_exists('author_id',$author_columns)); + $this->assertTrue(array_key_exists('author_id',$author_columns)); } public function test_columns_nullable() { $author_columns = $this->conn->columns('authors'); - $this->assert_false($author_columns['author_id']->nullable); - $this->assert_true($author_columns['parent_author_id']->nullable); + $this->assertFalse($author_columns['author_id']->nullable); + $this->assertTrue($author_columns['parent_author_id']->nullable); } public function test_columns_pk() { $author_columns = $this->conn->columns('authors'); - $this->assert_true($author_columns['author_id']->pk); - $this->assert_false($author_columns['parent_author_id']->pk); + $this->assertTrue($author_columns['author_id']->pk); + $this->assertFalse($author_columns['parent_author_id']->pk); } public function test_columns_sequence() @@ -155,36 +155,36 @@ public function test_columns_sequence() if ($this->conn->supports_sequences()) { $author_columns = $this->conn->columns('authors'); - $this->assert_equals('authors_author_id_seq',$author_columns['author_id']->sequence); + $this->assertEquals('authors_author_id_seq',$author_columns['author_id']->sequence); } } public function test_columns_default() { $author_columns = $this->conn->columns('authors'); - $this->assert_equals('default_name',$author_columns['name']->default); + $this->assertEquals('default_name',$author_columns['name']->default); } public function test_columns_type() { $author_columns = $this->conn->columns('authors'); - $this->assert_equals('varchar',substr($author_columns['name']->raw_type,0,7)); - $this->assert_equals(Column::STRING,$author_columns['name']->type); - $this->assert_equals(25,$author_columns['name']->length); + $this->assertEquals('varchar',substr($author_columns['name']->raw_type,0,7)); + $this->assertEquals(Column::STRING,$author_columns['name']->type); + $this->assertEquals(25,$author_columns['name']->length); } public function test_columns_text() { $author_columns = $this->conn->columns('authors'); - $this->assert_equals('text',$author_columns['some_text']->raw_type); - $this->assert_equals(null,$author_columns['some_text']->length); + $this->assertEquals('text',$author_columns['some_text']->raw_type); + $this->assertEquals(null,$author_columns['some_text']->length); } public function test_columns_time() { $author_columns = $this->conn->columns('authors'); - $this->assert_equals('time',$author_columns['some_time']->raw_type); - $this->assert_equals(Column::TIME,$author_columns['some_time']->type); + $this->assertEquals('time',$author_columns['some_time']->raw_type); + $this->assertEquals(Column::TIME,$author_columns['some_time']->type); } public function test_query() @@ -192,11 +192,11 @@ public function test_query() $sth = $this->conn->query('SELECT * FROM authors'); while (($row = $sth->fetch())) - $this->assert_not_null($row); + $this->assertNotNull($row); $sth = $this->conn->query('SELECT * FROM authors WHERE author_id=1'); $row = $sth->fetch(); - $this->assert_equals('Tito',$row['name']); + $this->assertEquals('Tito',$row['name']); } /** @@ -219,8 +219,8 @@ public function test_fetch() $ids[] = $row['author_id']; } - $this->assert_equals(3,$i); - $this->assert_equals(array(1,2,3),$ids); + $this->assertEquals(3,$i); + $this->assertEquals(array(1,2,3),$ids); } public function test_query_with_params() @@ -228,44 +228,44 @@ public function test_query_with_params() $x=array('Bill Clinton','Tito'); $sth = $this->conn->query('SELECT * FROM authors WHERE name IN(?,?) ORDER BY name DESC',$x); $row = $sth->fetch(); - $this->assert_equals('Tito',$row['name']); + $this->assertEquals('Tito',$row['name']); $row = $sth->fetch(); - $this->assert_equals('Bill Clinton',$row['name']); + $this->assertEquals('Bill Clinton',$row['name']); $row = $sth->fetch(); - $this->assert_equals(null,$row); + $this->assertEquals(null,$row); } public function test_insert_id_should_return_explicitly_inserted_id() { $this->conn->query('INSERT INTO authors(author_id,name) VALUES(99,\'name\')'); - $this->assert_true($this->conn->insert_id() > 0); + $this->assertTrue($this->conn->insert_id() > 0); } public function test_insert_id() { $this->conn->query("INSERT INTO authors(name) VALUES('name')"); - $this->assert_true($this->conn->insert_id() > 0); + $this->assertTrue($this->conn->insert_id() > 0); } public function test_insert_id_with_params() { $x = array('name'); $this->conn->query('INSERT INTO authors(name) VALUES(?)',$x); - $this->assert_true($this->conn->insert_id() > 0); + $this->assertTrue($this->conn->insert_id() > 0); } public function test_inflection() { $columns = $this->conn->columns('authors'); - $this->assert_equals('parent_author_id',$columns['parent_author_id']->inflected_name); + $this->assertEquals('parent_author_id',$columns['parent_author_id']->inflected_name); } public function test_escape() { $s = "Bob's"; - $this->assert_not_equals($s,$this->conn->escape($s)); + $this->assertNotEquals($s,$this->conn->escape($s)); } public function test_columnsx() @@ -277,27 +277,27 @@ public function test_columnsx() $names = array_filter(array_map('strtolower',$names),function($s) { return $s !== 'some_time'; }); foreach ($names as $field) - $this->assert_true(array_key_exists($field,$columns)); + $this->assertTrue(array_key_exists($field,$columns)); - $this->assert_equals(true,$columns['author_id']->pk); - $this->assert_equals('int',$columns['author_id']->raw_type); - $this->assert_equals(Column::INTEGER,$columns['author_id']->type); - $this->assert_true($columns['author_id']->length > 1); - $this->assert_false($columns['author_id']->nullable); + $this->assertEquals(true,$columns['author_id']->pk); + $this->assertEquals('int',$columns['author_id']->raw_type); + $this->assertEquals(Column::INTEGER,$columns['author_id']->type); + $this->assertTrue($columns['author_id']->length > 1); + $this->assertFalse($columns['author_id']->nullable); - $this->assert_equals(false,$columns['parent_author_id']->pk); - $this->assert_true($columns['parent_author_id']->nullable); + $this->assertEquals(false,$columns['parent_author_id']->pk); + $this->assertTrue($columns['parent_author_id']->nullable); - $this->assert_equals('varchar',substr($columns['name']->raw_type,0,7)); - $this->assert_equals(Column::STRING,$columns['name']->type); - $this->assert_equals(25,$columns['name']->length); + $this->assertEquals('varchar',substr($columns['name']->raw_type,0,7)); + $this->assertEquals(Column::STRING,$columns['name']->type); + $this->assertEquals(25,$columns['name']->length); } public function test_columns_decimal() { $columns = $this->conn->columns('books'); - $this->assert_equals(Column::DECIMAL,$columns['special']->type); - $this->assert_true($columns['special']->length >= 10); + $this->assertEquals(Column::DECIMAL,$columns['special']->type); + $this->assertTrue($columns['special']->length >= 10); } private function limit($offset, $limit) @@ -310,54 +310,54 @@ private function limit($offset, $limit) public function test_limit() { - $this->assert_equals(array(2,1),$this->limit(1,2)); + $this->assertEquals(array(2,1),$this->limit(1,2)); } public function test_limit_to_first_record() { - $this->assert_equals(array(3),$this->limit(0,1)); + $this->assertEquals(array(3),$this->limit(0,1)); } public function test_limit_to_last_record() { - $this->assert_equals(array(1),$this->limit(2,1)); + $this->assertEquals(array(1),$this->limit(2,1)); } public function test_limit_with_null_offset() { - $this->assert_equals(array(3),$this->limit(null,1)); + $this->assertEquals(array(3),$this->limit(null,1)); } public function test_limit_with_nulls() { - $this->assert_equals(array(),$this->limit(null,null)); + $this->assertEquals(array(),$this->limit(null,null)); } public function test_fetch_no_results() { $sth = $this->conn->query('SELECT * FROM authors WHERE author_id=65534'); - $this->assert_equals(null,$sth->fetch()); + $this->assertEquals(null,$sth->fetch()); } public function test_tables() { - $this->assert_true(count($this->conn->tables()) > 0); + $this->assertTrue(count($this->conn->tables()) > 0); } public function test_query_column_info() { - $this->assert_greater_than(0,count($this->conn->query_column_info("authors"))); + $this->assertGreaterThan(0,count($this->conn->query_column_info("authors"))); } public function test_query_table_info() { - $this->assert_greater_than(0,count($this->conn->query_for_tables())); + $this->assertGreaterThan(0,count($this->conn->query_for_tables())); } public function test_query_table_info_must_return_one_field() { $sth = $this->conn->query_for_tables(); - $this->assert_equals(1,count($sth->fetch())); + $this->assertEquals(1,count($sth->fetch())); } public function test_transaction_commit() @@ -368,7 +368,7 @@ public function test_transaction_commit() $this->conn->query("insert into authors(author_id,name) values(9999,'blahhhhhhhh')"); $this->conn->commit(); - $this->assert_equals($original+1,$this->conn->query_and_fetch_one("select count(*) from authors")); + $this->assertEquals($original+1,$this->conn->query_and_fetch_one("select count(*) from authors")); } public function test_transaction_rollback() @@ -379,7 +379,7 @@ public function test_transaction_rollback() $this->conn->query("insert into authors(author_id,name) values(9999,'blahhhhhhhh')"); $this->conn->rollback(); - $this->assert_equals($original,$this->conn->query_and_fetch_one("select count(*) from authors")); + $this->assertEquals($original,$this->conn->query_and_fetch_one("select count(*) from authors")); } public function test_show_me_a_useful_pdo_exception_message() @@ -388,7 +388,7 @@ public function test_show_me_a_useful_pdo_exception_message() $this->conn->query('select * from an_invalid_column'); $this->fail(); } catch (Exception $e) { - $this->assert_equals(1,preg_match('/(an_invalid_column)|(exist)/',$e->getMessage())); + $this->assertEquals(1,preg_match('/(an_invalid_column)|(exist)/',$e->getMessage())); } } @@ -398,20 +398,20 @@ public function test_quote_name_does_not_over_quote() $q = $c::$QUOTE_CHARACTER; $qn = function($s) use ($c) { return $c->quote_name($s); }; - $this->assert_equals("{$q}string", $qn("{$q}string")); - $this->assert_equals("string{$q}", $qn("string{$q}")); - $this->assert_equals("{$q}string{$q}", $qn("{$q}string{$q}")); + $this->assertEquals("{$q}string", $qn("{$q}string")); + $this->assertEquals("string{$q}", $qn("string{$q}")); + $this->assertEquals("{$q}string{$q}", $qn("{$q}string{$q}")); } public function test_datetime_to_string() { $datetime = '2009-01-01 01:01:01 EST'; - $this->assert_equals($datetime,$this->conn->datetime_to_string(date_create($datetime))); + $this->assertEquals($datetime,$this->conn->datetime_to_string(date_create($datetime))); } public function test_date_to_string() { $datetime = '2009-01-01'; - $this->assert_equals($datetime,$this->conn->date_to_string(date_create($datetime))); + $this->assertEquals($datetime,$this->conn->date_to_string(date_create($datetime))); } } diff --git a/test/helpers/DatabaseTest.php b/test/helpers/DatabaseTest.php index a597b768d..b8ebd62a4 100644 --- a/test/helpers/DatabaseTest.php +++ b/test/helpers/DatabaseTest.php @@ -1,13 +1,13 @@ conn = ActiveRecord\ConnectionManager::get_connection($connection_name); } catch (ActiveRecord\DatabaseException $e) { - $this->mark_test_skipped($connection_name . ' failed to connect. '.$e->getMessage()); + $this->markTestSkipped($connection_name . ' failed to connect. '.$e->getMessage()); } $GLOBALS['ACTIVERECORD_LOG'] = false; @@ -43,14 +43,14 @@ public function set_up($connection_name=null) $GLOBALS['ACTIVERECORD_LOG'] = true; } - public function tear_down() + public function tearDown() { ActiveRecord\Config::instance()->set_date_class($this->original_date_class); if ($this->original_default_connection) ActiveRecord\Config::instance()->set_default_connection($this->original_default_connection); } - public function assert_exception_message_contains($contains, $closure) + public function assertExceptionMessageContains($contains, $closure) { $message = ""; @@ -69,14 +69,14 @@ public function assert_exception_message_contains($contains, $closure) * Takes database specific quotes into account by removing them. So, this won't * work if you have actual quotes in your strings. */ - public function assert_sql_has($needle, $haystack) + public function assertSqlHas($needle, $haystack) { $needle = str_replace(array('"','`'),'',$needle); $haystack = str_replace(array('"','`'),'',$haystack); return $this->assertContains($needle, $haystack); } - public function assert_sql_doesnt_has($needle, $haystack) + public function assertSqlDoesntHas($needle, $haystack) { $needle = str_replace(array('"','`'),'',$needle); $haystack = str_replace(array('"','`'),'',$haystack); diff --git a/test/helpers/SnakeCase_PHPUnit_Framework_TestCase.php b/test/helpers/SnakeCase_PHPUnit_Framework_TestCase.php deleted file mode 100644 index 1016aa044..000000000 --- a/test/helpers/SnakeCase_PHPUnit_Framework_TestCase.php +++ /dev/null @@ -1,63 +0,0 @@ -camelize($meth); - - if (method_exists($this, $camel_cased_method)) - return call_user_func_array(array($this, $camel_cased_method), $args); - - $class_name = get_called_class(); - $trace = debug_backtrace(); - die("PHP Fatal Error: Call to undefined method $class_name::$meth() in {$trace[1]['file']} on line {$trace[1]['line']}" . PHP_EOL); - } - - public function setUp() - { - if (method_exists($this,'set_up')) - call_user_func_array(array($this,'set_up'),func_get_args()); - } - - public function tearDown() - { - if (method_exists($this,'tear_down')) - call_user_func_array(array($this,'tear_down'),func_get_args()); - } - - private function setup_assert_keys($args) - { - $last = count($args)-1; - $keys = array_slice($args,0,$last); - $array = $args[$last]; - return array($keys,$array); - } - - public function assert_has_keys(/* $keys..., $array */) - { - list($keys,$array) = $this->setup_assert_keys(func_get_args()); - - $this->assert_not_null($array,'Array was null'); - - foreach ($keys as $name) - $this->assert_array_has_key($name,$array); - } - - public function assert_doesnt_has_keys(/* $keys..., $array */) - { - list($keys,$array) = $this->setup_assert_keys(func_get_args()); - - foreach ($keys as $name) - $this->assert_array_not_has_key($name,$array); - } - - public function assert_is_a($expected_class, $object) - { - $this->assert_equals($expected_class,get_class($object)); - } - - public function assert_datetime_equals($expected, $actual) - { - $this->assert_equals($expected->format(DateTime::ISO8601),$actual->format(DateTime::ISO8601)); - } -} diff --git a/test/helpers/TestCase.php b/test/helpers/TestCase.php new file mode 100644 index 000000000..671513dda --- /dev/null +++ b/test/helpers/TestCase.php @@ -0,0 +1,39 @@ +setupAssertKeys(func_get_args()); + + $this->assertNotNull($array,'Array was null'); + + foreach ($keys as $name) + $this->assertArrayHasKey($name,$array); + } + + public function assertDoesntHasKeys(/* $keys..., $array */) + { + list($keys,$array) = $this->setupAssertKeys(func_get_args()); + + foreach ($keys as $name) + $this->assertArrayNotHasKey($name,$array); + } + + public function assertIsA($expected_class, $object) + { + $this->assertEquals($expected_class,get_class($object)); + } + + public function assertDateTimeEquals($expected, $actual) + { + $this->assertEquals($expected->format(DateTime::ISO8601),$actual->format(DateTime::ISO8601)); + } +} diff --git a/test/helpers/config.php b/test/helpers/config.php index a71243e14..26880c185 100644 --- a/test/helpers/config.php +++ b/test/helpers/config.php @@ -19,7 +19,7 @@ require_once 'vendor/autoload.php'; -require_once 'SnakeCase_PHPUnit_Framework_TestCase.php'; +require_once 'TestCase.php'; require_once 'DatabaseTest.php'; require_once 'AdapterTest.php';