-
Notifications
You must be signed in to change notification settings - Fork 52
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
Create Check_Result class #50
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
74765de
add check result class
jjgrainger 297a37c
add tests
jjgrainger 5b9351e
Merge branch 'trunk' into feature/create-check-result-class
jjgrainger c61dd90
remove Plugin_Context from Check_Result
jjgrainger a19ffbd
unset file from message data
jjgrainger 3326311
update Check_Result_Tests
jjgrainger a7d7a02
Merge branch 'trunk' into feature/create-check-result-class
jjgrainger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,179 @@ | ||
<?php | ||
/** | ||
* Tests for the Check_Result class. | ||
* | ||
* @package plugin-check | ||
*/ | ||
|
||
use WordPress\Plugin_Check\Checker\Check_Context; | ||
use WordPress\Plugin_Check\Checker\Check_Result; | ||
|
||
class Check_Result_Tests extends WP_UnitTestCase { | ||
/** | ||
* Check_Result instance. | ||
* | ||
* @var Check_Result | ||
*/ | ||
protected $check_result; | ||
|
||
public function set_up() { | ||
parent::set_up(); | ||
|
||
$check_context = new Check_Context( 'test-plugin/test-plugin.php' ); | ||
|
||
$this->check_result = new Check_Result( $check_context ); | ||
felixarntz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
public function test_plugin() { | ||
$this->assertInstanceOf( Check_Context::class, $this->check_result->plugin() ); | ||
felixarntz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// Check the Check_Context has the correct basename. | ||
$this->assertSame( 'test-plugin/test-plugin.php', $this->check_result->plugin()->basename() ); | ||
} | ||
|
||
public function test_add_message_with_warning() { | ||
$this->check_result->add_message( | ||
false, | ||
'Warning message', | ||
array( | ||
'code' => 'test_warning', | ||
'file' => 'test-plugin/test-plugin.php', | ||
'line' => 12, | ||
'column' => 40, | ||
) | ||
); | ||
|
||
$warnings = $this->check_result->get_warnings(); | ||
|
||
// Tests that warnings contains an error. | ||
$this->assertNotEmpty( $warnings ); | ||
|
||
// Tests warnings count incremented correctly. | ||
$this->assertEquals( 1, $this->check_result->get_warning_count() ); | ||
|
||
// Tests no errors were added or error count incrememeted. | ||
$this->assertEmpty( $this->check_result->get_errors() ); | ||
$this->assertEquals( 0, $this->check_result->get_error_count() ); | ||
|
||
// Tests the warning exists in the array. | ||
$expected = array( | ||
'message' => 'Warning message', | ||
'code' => 'test_warning', | ||
); | ||
|
||
$this->assertEquals( $expected, $warnings['test-plugin.php'][12][40][0] ); | ||
} | ||
|
||
public function test_add_message_with_error() { | ||
$this->check_result->add_message( | ||
true, | ||
'Error message', | ||
array( | ||
'code' => 'test_error', | ||
'file' => 'test-plugin/test-plugin.php', | ||
'line' => 22, | ||
'column' => 30, | ||
) | ||
); | ||
|
||
$errors = $this->check_result->get_errors(); | ||
|
||
// Tests that errors contains an error. | ||
$this->assertNotEmpty( $errors ); | ||
|
||
// Tests errors count incremented correctly. | ||
$this->assertEquals( 1, $this->check_result->get_error_count() ); | ||
|
||
// Tests no warnings were added or warnings count incrememeted. | ||
$this->assertEmpty( $this->check_result->get_warnings() ); | ||
$this->assertEquals( 0, $this->check_result->get_warning_count() ); | ||
|
||
// Tests the error exists in the array. | ||
$expected = array( | ||
'message' => 'Error message', | ||
'code' => 'test_error', | ||
); | ||
|
||
$this->assertEquals( $expected, $errors['test-plugin.php'][22][30][0] ); | ||
} | ||
|
||
public function test_get_errors() { | ||
$this->assertEmpty( $this->check_result->get_errors() ); | ||
} | ||
|
||
public function test_get_errors_with_errors() { | ||
$this->check_result->add_message( | ||
true, | ||
'Error message', | ||
array( | ||
'code' => 'test_error', | ||
'file' => 'test-plugin/test-plugin.php', | ||
'line' => 22, | ||
'column' => 30, | ||
) | ||
); | ||
|
||
$errors = $this->check_result->get_errors(); | ||
|
||
// Tests errors are not empty. | ||
$this->assertNotEmpty( $errors ); | ||
|
||
// Tests the error exists in the array. | ||
$expected = array( | ||
'message' => 'Error message', | ||
'code' => 'test_error', | ||
); | ||
|
||
$this->assertEquals( $expected, $errors['test-plugin.php'][22][30][0] ); | ||
} | ||
|
||
public function test_get_warnings() { | ||
$this->assertEmpty( $this->check_result->get_warnings() ); | ||
} | ||
|
||
public function test_get_warnings_with_warnings() { | ||
$this->check_result->add_message( | ||
false, | ||
'Warning message', | ||
array( | ||
'code' => 'test_warning', | ||
'file' => 'test-plugin/test-plugin.php', | ||
'line' => 22, | ||
'column' => 30, | ||
) | ||
); | ||
|
||
$warnings = $this->check_result->get_warnings(); | ||
|
||
// Tests warnings are not empty. | ||
$this->assertNotEmpty( $warnings ); | ||
|
||
// Tests the warning exists in the array. | ||
$expected = array( | ||
'message' => 'Warning message', | ||
'code' => 'test_warning', | ||
); | ||
|
||
$this->assertEquals( $expected, $warnings['test-plugin.php'][22][30][0] ); | ||
} | ||
|
||
public function test_get_warning_count() { | ||
$this->assertEquals( 0, $this->check_result->get_warning_count() ); | ||
} | ||
|
||
public function test_get_warning_count_with_message() { | ||
$this->check_result->add_message( false, 'Warning message' ); | ||
|
||
$this->assertEquals( 1, $this->check_result->get_warning_count() ); | ||
} | ||
|
||
public function test_get_error_count() { | ||
$this->assertEquals( 0, $this->check_result->get_error_count() ); | ||
} | ||
|
||
public function test_get_error_count_with_message() { | ||
$this->check_result->add_message( true, 'Error message' ); | ||
|
||
$this->assertEquals( 1, $this->check_result->get_error_count() ); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI no need to do any formal doc blocks in tests. It's good to add comments when a test method does things that may not be immediately clear on why it does so, but generally tests don't need docs.
Obviously not a blocker, it's okay to have this. But not needed :)