Skip to content

Commit

Permalink
Merge pull request #43 from sectsect/feature/phpunit
Browse files Browse the repository at this point in the history
[PHPUnit] add `@covers` annotations to test classes and methods
  • Loading branch information
sectsect committed Apr 29, 2024
2 parents 1f7bab1 + ea82f1a commit def5362
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions tests/FunctionTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
/**
* Class FunctionsTest
* Tests the functionality of functions in functions.php.
* @coversDefaultClass Functions
*/
class FunctionsTest extends WP_UnitTestCase {
/**
* @dataProvider providerTruncateMiddle
* @covers ::google_ss2db_truncate_middle
*/
public function test_google_ss2db_truncate_middle( $input, $max_chars, $expected ) {
require_once 'functions/functions.php'; // Include the file where the function is defined.
Expand All @@ -25,6 +27,7 @@ public function providerTruncateMiddle() {

/**
* Tests the output of the google_ss2db_options_pagination function.
* @covers ::google_ss2db_options_pagination
*/
public function testPaginationOutput() {
// Pagination settings.
Expand Down
3 changes: 3 additions & 0 deletions tests/GoogleSpreadsheetToDBActivatorTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
* Class for testing the Google_Spreadsheet_To_DB_Activator activation functionality.
*
* This class extends WP_UnitTestCase to test the activation method of the Google_Spreadsheet_To_DB_Activator class.
* @covers Google_Spreadsheet_To_DB_Activator::activate
*/

class Test_Google_Spreadsheet_To_DB_Activator extends WP_UnitTestCase {

/**
* Test the activate method when no previous version is installed.
* @covers Google_Spreadsheet_To_DB_Activator::activate
*/
public function test_activate_no_previous_version() {
global $wpdb;
Expand All @@ -33,6 +35,7 @@ public function test_activate_no_previous_version() {

/**
* Test the activate method when the installed version is outdated.
* @covers Google_Spreadsheet_To_DB_Activator::activate
*/
public function test_activate_outdated_version() {
global $wpdb;
Expand Down
8 changes: 8 additions & 0 deletions tests/GoogleSpreadsheetToDBQueryTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
/**
* Class Test_Google_Spreadsheet_To_DB_Query
* Tests the Google_Spreadsheet_To_DB_Query class functionality.
* @covers Google_Spreadsheet_To_DB_Query
*/
class Google_Spreadsheet_To_DB_Query_Test extends WP_UnitTestCase {
protected $mock_data;
Expand Down Expand Up @@ -53,6 +54,7 @@ public function setUp(): void {

/**
* Test getting all rows.
* @covers Google_Spreadsheet_To_DB_Query::getrow
*/
public function test_get_all_rows() {
$sheet = $this->getMockBuilder( Google_Spreadsheet_To_DB_Query::class )
Expand All @@ -69,6 +71,7 @@ public function test_get_all_rows() {

/**
* Test getting 3 rows starting from the 4th row, ordered by ID in ascending order.
* @covers Google_Spreadsheet_To_DB_Query::getrow
*/
public function test_get_3_rows_from_4th_ascending_by_id() {
$args = array(
Expand All @@ -94,6 +97,7 @@ public function test_get_3_rows_from_4th_ascending_by_id() {

/**
* Test getting a row with a specific ID.
* @covers Google_Spreadsheet_To_DB_Query::getrow
*/
public function test_get_row_with_specific_id() {
$args = array(
Expand Down Expand Up @@ -128,6 +132,7 @@ function ( $row ) {

/**
* Test getting 3 rows with a specific worksheet name, ordered by ID.
* @covers Google_Spreadsheet_To_DB_Query::getrow
*/
public function test_get_3_rows_with_specific_worksheet_ordered_by_id() {
$args = array(
Expand Down Expand Up @@ -178,6 +183,7 @@ function ( $a, $b ) {

/**
* Test getting rows with a specific sheet name.
* @covers Google_Spreadsheet_To_DB_Query::getrow
*/
public function test_get_rows_with_specific_sheet_name() {
$args = array(
Expand Down Expand Up @@ -212,6 +218,7 @@ function ( $row ) {

/**
* Test getting rows with a specific title.
* @covers Google_Spreadsheet_To_DB_Query::getrow
*/
public function test_get_rows_with_specific_title() {
$args = array(
Expand Down Expand Up @@ -246,6 +253,7 @@ function ( $row ) {

/**
* Test getting the 2nd row with a date greater than or equal to '2023-06-03 12:00:00' and a specific worksheet name, ordered by ID in descending order.
* @covers Google_Spreadsheet_To_DB_Query::getrow
*/
public function test_get_2nd_row_with_date_gte_and_specific_worksheet_ordered_by_id_desc() {
$args = array(
Expand Down

0 comments on commit def5362

Please sign in to comment.