Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions test/ActiveRecordTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -453,16 +453,14 @@ public function test_setter_with_same_name_as_an_attribute()
public function test_getter()
{
$book = Book::first();
$this->assertEquals(strtoupper($book->name), $book->upper_name);
$this->assertEquals("ANCIENT ART OF MAIN TANKING", $book->upper_name);
}

public function test_getter_with_same_name_as_an_attribute()
{
Book::$use_custom_get_name_getter = true;
$book = new Book();
$book->name = 'bob';
$this->assertEquals('BOB', $book->name);
Book::$use_custom_get_name_getter = false;
$book->publisher = 'Random House';
$this->assertEquals('RANDOM HOUSE', $book->publisher);
}

public function test_setting_invalid_date_should_set_date_to_null()
Expand Down
10 changes: 5 additions & 5 deletions test/SerializationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function test_methods_takes_a_string()
$this->assertEquals('ANCIENT ART OF MAIN TANKING', $a['upper_name']);
}

// methods added last should we shuld have value of the method in our json
// methods added last should have value of the method in our json
// rather than the regular attribute value
public function test_methods_method_same_as_attribute()
{
Expand Down Expand Up @@ -173,13 +173,13 @@ public function test_only_method()
public function test_to_csv()
{
$book = Book::find(1);
$this->assertEquals('1,1,2,"Ancient Art of Main Tanking",0,0', $book->to_csv());
$this->assertEquals('1,1,2,"Ancient Art of Main Tanking","Random House",0,0', $book->to_csv());
}

public function test_to_csv_only_header()
{
$book = Book::find(1);
$this->assertEquals('book_id,author_id,secondary_author_id,name,numeric_test,special',
$this->assertEquals('book_id,author_id,secondary_author_id,name,publisher,numeric_test,special',
$book->to_csv(['only_header'=>true])
);
}
Expand All @@ -205,14 +205,14 @@ public function test_to_csv_with_custom_delimiter()
{
$book = Book::find(1);
CsvSerializer::$delimiter=';';
$this->assertEquals('1;1;2;"Ancient Art of Main Tanking";0;0', $book->to_csv());
$this->assertEquals('1;1;2;"Ancient Art of Main Tanking";"Random House";0;0', $book->to_csv());
}

public function test_to_csv_with_custom_enclosure()
{
$book = Book::find(1);
CsvSerializer::$delimiter=',';
CsvSerializer::$enclosure="'";
$this->assertEquals("1,1,2,'Ancient Art of Main Tanking',0,0", $book->to_csv());
$this->assertEquals("1,1,2,'Ancient Art of Main Tanking','Random House',0,0", $book->to_csv());
}
}
6 changes: 3 additions & 3 deletions test/fixtures/books.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
book_id,author_id,secondary_author_id,name,special
1,1,2,"Ancient Art of Main Tanking",0
2,2,2,"Another Book",0
book_id,author_id,secondary_author_id,name,publisher,special
1,1,2,"Ancient Art of Main Tanking","Random House",0
2,2,2,"Another Book","Penguin",0
16 changes: 5 additions & 11 deletions test/models/Book.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,24 @@ class Book extends Model
{
public static array $belongs_to = ['author'];
public static $has_one = [];
public static $use_custom_get_name_getter = false;

public function upper_name()
{
return strtoupper($this->name);
return strtoupper($this->name); // keep?
}

public function name()
{
return strtolower($this->name);
return strtolower($this->name); // keep
}

public function get_name()
public function get_publisher()
{
if (self::$use_custom_get_name_getter) {
return strtoupper($this->read_attribute('name'));
}

return $this->read_attribute('name');
return strtoupper($this->read_attribute('publisher')); // keep
}

public function get_upper_name()
{
return strtoupper($this->name);
return strtoupper($this->name); // keep
}

public function get_lower_name()
Expand Down
1 change: 1 addition & 0 deletions test/sql/mysql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ CREATE TABLE books(
Author_Id INT,
secondary_author_id INT,
name VARCHAR(50),
publisher VARCHAR(50),
numeric_test VARCHAR(10) DEFAULT '0',
special NUMERIC(10,2) DEFAULT 0
);
Expand Down
1 change: 1 addition & 0 deletions test/sql/pgsql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ CREATE TABLE books(
author_id INT,
secondary_author_id INT,
name VARCHAR(50),
publisher VARCHAR(50),
numeric_test VARCHAR(10) DEFAULT '0',
special NUMERIC(10,2) DEFAULT 0.0
);
Expand Down
1 change: 1 addition & 0 deletions test/sql/sqlite.sql
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ CREATE TABLE books(
Author_Id INT,
secondary_author_id INT,
name VARCHAR(50),
publisher VARCHAR(50),
numeric_test VARCHAR(10) DEFAULT '0',
special NUMERIC(10,2) DEFAULT 0
);
Expand Down