Skip to content

Commit

Permalink
Add tests for Controller::__construct() (#219)
Browse files Browse the repository at this point in the history
  • Loading branch information
costdev authored Dec 1, 2024
1 parent d4358cf commit db3322e
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
6 changes: 6 additions & 0 deletions includes/class-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public function __construct() {
/**
* Enable API Rewrites based on the Users settings.
*
* @codeCoverageIgnore Side-effects are from other methods already covered by tests.
*
* @return void
*/
private function api_rewrite() {
Expand All @@ -52,6 +54,8 @@ private function api_rewrite() {
/**
* Ajax action to clear the Log file.
*
* @codeCoverageIgnore Cannot be tested. Results in script termination.
*
* @return void
*/
public function clear_log() {
Expand Down Expand Up @@ -82,6 +86,8 @@ public function clear_log() {
/**
* Ajax action to read the Log file.
*
* @codeCoverageIgnore Cannot be tested. Results in script termination.
*
* @return void
*/
public function read_log() {
Expand Down
44 changes: 44 additions & 0 deletions tests/phpunit/tests/Controller/Controller_ConstructTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
/**
* Class Controller_ConstructTest
*
* @package AspireUpdate
*/

/**
* Tests for Controller::__construct()
*
* @covers \AspireUpdate\Controller::__construct
*/
class Controller_ConstructTest extends WP_UnitTestCase {
/**
* Test that hooks are added.
*
* @dataProvider data_hooks_and_methods
*
* @string $hook The hook's name.
* @string $method The method to hook.
*/
public function test_should_add_hooks( $hook, $method ) {
$controller = new AspireUpdate\Controller();
$this->assertIsInt( has_action( $hook, [ $controller, $method ] ) );
}

/**
* Data provider.
*
* @return array[]
*/
public function data_hooks_and_methods() {
return [
'wp_ajax_aspireupdate_clear_log -> clear_log' => [
'hook' => 'wp_ajax_aspireupdate_clear_log',
'method' => 'clear_log',
],
'wp_ajax_aspireupdate_read_log -> read_log' => [
'hook' => 'wp_ajax_aspireupdate_read_log',
'method' => 'read_log',
],
];
}
}

0 comments on commit db3322e

Please sign in to comment.