Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial refactor unit test file #1055

Draft
wants to merge 5 commits into
base: development
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
117 changes: 77 additions & 40 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
<?php

namespace GFPDF\Tests;
namespace GFPDF\Tests\Controller;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, we should use the same namespace as the class being tested.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed on recent push.


use GFPDF\Controller\Controller_Actions;
use GFPDF\Model\Model_Actions;
use GFPDF\View\View_Actions;

use WP_UnitTestCase;

use Exception;

/**
* Test Gravity PDF Actions functionality
Expand All @@ -26,7 +23,7 @@
*
* @group actions
*/
class Test_Actions extends WP_UnitTestCase {
class ActionTest extends \WP_UnitTestCase {
/**
* Our Controller
*
Expand Down Expand Up @@ -78,9 +75,10 @@ public function setUp() {
*
* @since 4.0
*/
public function test_actions() {
public function test_add_actions() {
$this->assertSame( 10, has_action( 'admin_init', [ $this->controller, 'route' ] ) );
$this->assertSame( 20, has_action( 'admin_init', [ $this->controller, 'route_notices' ] ) );

}

/**
Expand Down Expand Up @@ -247,7 +245,7 @@ function( $routes ) {
/* Fail capability check */
try {
$this->controller->route();
} catch ( Exception $e ) {
} catch ( \Exception $e ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should look at utilising PHPUnit's @expectException instead of running the test this way. https://phpunit.de/manual/6.5/en/writing-tests-for-phpunit.html#writing-tests-for-phpunit.exceptions

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied and use WPDieException

/* Expected */
}

Expand Down