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

Relationships with custom key names #6

Open
matalina opened this issue May 30, 2013 · 2 comments
Open

Relationships with custom key names #6

matalina opened this issue May 30, 2013 · 2 comments

Comments

@matalina
Copy link

Below is the error I get.

1) PageTest::testPageHasOnePage
Mockery\Exception\NoMatchingExpectationException: No matching handler found for page::hasOne("Page", 
"parent_id"). Either the method was unexpected or its arguments matched no expected argument list for this method



C:\wamp\www\squigglemd\vendor\mockery\mockery\library\Mockery\ExpectationDirector.php:93
C:\wamp\www\squigglemd\app\models\Page.php:18
C:\wamp\www\squigglemd\vendor\way\laravel-test-helpers\src\Way\Tests\ModelHelpers.php:59
C:\wamp\www\squigglemd\vendor\way\laravel-test-helpers\src\Way\Tests\ModelHelpers.php:36
C:\wamp\www\squigglemd\app\tests\PageTest.php:34

For the following model:

class Page extends Post {
    protected $guarded = array();

    protected $table = 'pages';

    public static $rules = array(
        'slug' => 'required|unique:posts',
        'title' => 'required',
        'user_id' => 'required|integer',
        'parent_id' => 'required|integer', 
        'order' => 'required|integer'
    );

    public function pages()
    {
        return $this->hasOne('Page', 'parent_id');
    }
}

And the test code:

    protected function _cleanUp()
    {
        $app = $this->createApplication();

        $app->make('artisan')->call('migrate:refresh');
        //Artisan::call('migrate:refresh');

        $page = new page();
        $page->slug = 'testing';
        $page->title = 'Testing';
        $page->user_id = 1;
        $page->parent_id = 0;
        $page->order = 0;

        $this->page = $page;

    }

    /** Relationships **/

    public function testPageHasOnePage()
    {
        $this->_cleanUp();

        $this->assertHasOne('pages', 'page');
    }

It passes when I remove the parent_id from the hasOne relationship.

@sorora
Copy link
Contributor

sorora commented Jun 1, 2013

I also have this issue. It appears to come from Mockery only expecting one piece of information back, however I have no idea how to add "optional withs" to mockery which I imagine would possible fix it.

@sorora
Copy link
Contributor

sorora commented Jun 1, 2013

https://github.com/sorora/Laravel-Test-Helpers/commit/4658c228959f03ca46a4c8c5bdfdfb2f34fe65b4 ... unfortunately I seem to stupid to of applied it in this issue thread. A proposed fix has been found though :-).

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

No branches or pull requests

2 participants