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

JSON Cast exception test cases #1911

Merged
merged 9 commits into from
Apr 7, 2019
Merged

JSON Cast exception test cases #1911

merged 9 commits into from
Apr 7, 2019

Conversation

atishhamte
Copy link
Contributor

@atishhamte atishhamte commented Apr 3, 2019

W.r.t #512 Adding test scenarios to increase the coverage of Cast Exception
WIP JSON Cast exception test cases.

Checklist:

  • Securely signed commits
  • Component(s) with PHPdocs
  • Unit testing, with >80% coverage
  • Conforms to style guide

@atishhamte
Copy link
Contributor Author

@lonnieezell @jim-parry, I am trying to write the test case for the private method castAsJson() of Entity Class.
Below is my code for the test scenario.

public function testCastAsJSONSyntaxError()
{
	$entity = new Entity();
	$method = $this->getPrivateMethodInvoker($entity,'castAsJson');
		
	$this->expectException(CastException::class);
	$this->expectExceptionMessage('Syntax error, malformed JSON');

	$method("'{ bar: \"baz\" }'", true);
}

At the time of build, I am getting error like,

1) CodeIgniter\EntityTest::testCastAsJSONSyntaxError
Failed asserting that exception of type "CodeIgniter\Exceptions\CastException" is thrown.

Could you please help me out with this. So I will be able to generate test scenarios.

@jim-parry
Copy link
Contributor

It looks like you are trying to json_decode a JSON string and expecting that to trigger an exception. That doesn't sound right.
Wouldn't you want to give the method something that can't be json_decoded? eg "( this is bad"

@atishhamte
Copy link
Contributor Author

atishhamte commented Apr 4, 2019

Thanks. It is working.

@jim-parry
Copy link
Contributor

Yes, it is reasonable.
Normally, however, you would thoroughly test on your system before pushing (and ending up with a bunch of commits), rather than using travis-ci to see if they work. Do you have the unit tests running on your system?

@atishhamte
Copy link
Contributor Author

I have tried but the system is not able to configure XDebug. I have tried many times but no success.
Also, I do not have Postgre, so all the test scenarios of it give an error.

@atishhamte atishhamte changed the title WIP JSON Cast exception test cases JSON Cast exception test cases Apr 4, 2019
@atishhamte atishhamte mentioned this pull request Apr 7, 2019
35 tasks
@jim-parry jim-parry merged commit 4c39668 into codeigniter4:develop Apr 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants