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

Adding Helper To Mock Result Sets In Testing #720

Merged
merged 11 commits into from Apr 29, 2017

Conversation

Fenikkusu
Copy link
Contributor

@Fenikkusu Fenikkusu commented Dec 23, 2016

Hello!

  • Type: new feature
  • Link to issue: NA

This pull request affects the following components: (please check boxes)

  • Library
  • Code Style
  • Documentation
  • Testing

In raising this pull request, I confirm the following (please check boxes):

  • I have read and understood the Contributing Guidelines?
  • I have checked that another pull request for this purpose does not exist.
  • I wrote some tests for this PR.

Small description of change:

I've added a trait for mocking a basic Result set. This comes in handy when doing unit tests and I don't want to have to actually connect to the DB to do so.

Thanks

Copy link
Member

@sergeyklay sergeyklay left a comment

Choose a reason for hiding this comment

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

@Fenikkusu Could you please take a look at my comments

* User: Charles.Martin
* Date: 12/13/2016
* Time: 12:41 PM
*/
Copy link
Member

Choose a reason for hiding this comment

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

Could you please use proper DocBlock or remove this at all

* Time: 12:41 PM
*/

namespace unit\Test\Traits;
Copy link
Member

Choose a reason for hiding this comment

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

unit\Test\Traits => Unit\Test\Traits

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After double checking this (comparing other files), I believe this should actually be 'Phalcon\Test\Test\Traits'?

Copy link
Member

Choose a reason for hiding this comment

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

Yes

use ResultSet;

/** @var \Phalcon\Test\Traits\ResultSet */
protected $testSubject = NULL;
Copy link
Member

Choose a reason for hiding this comment

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

NULL => null

}

public function testCanMockResultSet() {
$mockModel = $this->getMockBuilder('\Phalcon\Mvc\Model')
Copy link
Member

Choose a reason for hiding this comment

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

use Phalcon\Mvc\Model

$mockModel = $this->getMockBuilder(Model:class)

}

public function testCanUseOtherResultSetClasses() {
$mockResultset = $this->mockResultset([], '\Phalcon\Mvc\Model\Resultset\Simple');
Copy link
Member

Choose a reason for hiding this comment

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

Phalcon\Mvc\Model\Resultset\Simple;

$mockResultset = $this->mockResultset([], Simple::class);

$this->assertSame($mockData, $mockResultSet->toArray());
}

public function testCanMockEmptyResultSet() {
Copy link
Member

Choose a reason for hiding this comment

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

public function testCanMockEmptyResultSet() {

=>

public function testCanMockEmptyResultSet()
{

@@ -57,7 +57,9 @@ protected function _before()
*/
protected function _after()
{
$this->cleanup();
if (extension_loaded('aerospike')) {
$this->cleanup();
Copy link
Member

Choose a reason for hiding this comment

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

👍

*
* @return \PHPUnit_Framework_MockObject_MockObject|\Phalcon\Mvc\Model\Resultset|\Phalcon\Mvc\Model\ResultsetInterface
*/
public function mockResultSet(array $dataSet, $className = '\Phalcon\Mvc\Model\Resultset')
Copy link
Member

Choose a reason for hiding this comment

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

use Phalcon\Mvc\Model\Resultset;

public function mockResultSet(array $dataSet, $className = Resultset::class)
{

@Fenikkusu
Copy link
Contributor Author

...Apparently I made the changes but never finished them or pushed them up...go figure...oops.

@sergeyklay
Copy link
Member

@Fenikkusu Could you please rebase on 3.1.x branch

@sergeyklay
Copy link
Member

The 3.0.x branch is not longer supported. Could you please submit PR to the 3.2.x branch?

@Fenikkusu Fenikkusu changed the base branch from 3.0.x to 3.2.x April 12, 2017 14:49
@Fenikkusu
Copy link
Contributor Author

Updated, though it looks like the dump.sql may be out of date. Running Codeception locally is resulting in errors from EagerLoading and Prefixing.

@Fenikkusu
Copy link
Contributor Author

Ignore my previous comment regarding the dump.sql - DB wasn't populated.

@sergeyklay sergeyklay merged commit f639e04 into phalcon:3.2.x Apr 29, 2017
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