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

Unexpected website exception thrown while getting report with Request::processRequest(args) #11600

Closed
tassoman opened this issue Apr 7, 2017 · 4 comments
Labels
answered For when a question was asked and we referred to forum or answered it. c: Tests & QA For issues related to automated tests or making it easier to QA & test issues.

Comments

@tassoman
Copy link
Contributor

tassoman commented Apr 7, 2017

I'm writing a new plugin using this short snippet of code querying VisitsSummary.get API method, but unluckly.

    public static function getVisitsSummary()
    {
        Access::getInstance()->setSuperUserAccess();

        $report = Request::processRequest(self::$method, [
            'idSite' => self::$idSite,
            'date'   => self::$date,
            'period' => self::$period,
        ]);

        return $report;
    }

My unit test is throwing an exception:

Exception: An unexpected website was found in the request: website id was set to '1' .
I've tried passing idSite also as array but with no luck.

I've also tried calling the API directly (but isn't a good practice as shown in docs):

        $report = \Piwik\Plugins\VisitsSummary\API::getInstance()->get(
            self::$idSite,
            self::$date,
            self::$period
        );

In this case I got a more detailed backtrace:

Piwik\Exception\UnexpectedWebsiteFoundException: An unexpected website was found in the request: website id was set to '1' .

/home/dev/piwik/core/Site.php:128
/home/dev/piwik/plugins/SitesManager/API.php:195
/home/dev/piwik/core/Site.php:432
/home/dev/piwik/core/Site.php:494
/home/dev/piwik/core/Archive.php:215
/home/dev/piwik/plugins/VisitsSummary/API.php:28
/home/dev/piwik/plugins/RerVerify2/RerVerify2.php:45
/home/dev/piwik/plugins/RerVerify2/tests/Unit/RerVerifyTest.php:78

Reading the code looks like idSite argument get lost (empty) in its road to Site.php:128 but I can't really say where, because at UnexpectedWebsiteFoundException idSite stills 1.

Any help is appreciated, ciao!

@tassoman
Copy link
Contributor Author

tassoman commented Apr 7, 2017

This exception was talked about in: #8534 #8396 #7698

@tsteur
Copy link
Member

tsteur commented Apr 7, 2017

You would need to create an integration test (instead of unit test) and make sure to create a site for example in the setUp method of the test.

@tassoman
Copy link
Contributor Author

Ciao @tsteur I've switched the test to an Integration Test (using console generator) then I've added fixtures to setUp() but with no luck, the exception still there.

    public function setUp()
    {
        Fixture::createSuperUser();
        Fixture::createWebsite('2017-01-01 00:00:00');

        parent::setUp();
    }

@tsteur
Copy link
Member

tsteur commented Apr 15, 2017

Try to call the parent setUp first and then it should work I presume

@mattab mattab closed this as completed May 8, 2017
@mattab mattab added answered For when a question was asked and we referred to forum or answered it. c: Tests & QA For issues related to automated tests or making it easier to QA & test issues. labels May 8, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
answered For when a question was asked and we referred to forum or answered it. c: Tests & QA For issues related to automated tests or making it easier to QA & test issues.
Projects
None yet
Development

No branches or pull requests

3 participants