Completed
Push — master ( c2bc12...ef5bc2 )
by Dmitry
04:55
created

tests/acceptance/seller/SalesCest.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * Finance module for HiPanel
4
 *
5
 * @link      https://github.com/hiqdev/hipanel-module-finance
6
 * @package   hipanel-module-finance
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2015-2019, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hipanel\modules\finance\tests\acceptance\seller;
12
13
use hipanel\helpers\Url;
14
use hipanel\tests\_support\Page\IndexPage;
15
use hipanel\tests\_support\Page\Widget\Input\Dropdown;
16
use hipanel\tests\_support\Page\Widget\Input\Input;
17
use hipanel\tests\_support\Page\Widget\Input\Select2;
18
use hipanel\tests\_support\Step\Acceptance\Seller;
19
20
class SalesCest
21
{
22
    /**
23
     * @var IndexPage
24
     */
25
    private $index;
26
27
    public function _before(Seller $I)
28
    {
29
        $this->index = new IndexPage($I);
30
    }
31
32 View Code Duplication
    public function ensureIndexPageWorks(Seller $I)
33
    {
34
        $I->login();
35
        $I->needPage(Url::to('@sale'));
36
        $I->see('Sales', 'h1');
37
        $this->ensureICanSeeAdvancedSearchBox($I);
38
        $this->ensureICanSeeBulkBillSearchBox();
39
    }
40
41
    private function ensureICanSeeAdvancedSearchBox(Seller $I)
42
    {
43
        $this->index->containsFilters([
44
            Select2::asAdvancedSearch($I, 'Seller'),
45
            Select2::asAdvancedSearch($I, 'Buyer'),
46
            (Dropdown::asAdvancedSearch($I,'Object type'))->withItems([
0 ignored issues
show
It seems like you code against a specific sub-type and not the parent class hipanel\tests\_support\P...get\Input\TestableInput as the method withItems() does only exist in the following sub-classes of hipanel\tests\_support\P...get\Input\TestableInput: hipanel\tests\_support\Page\Widget\Input\Dropdown. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
47
                'Servers',
48
                'IP',
49
                'Accounts',
50
                'Clients',
51
                'Parts',
52
            ]),
53
            Select2::asAdvancedSearch($I, 'Tariff'),
54
            Input::asAdvancedSearch($I, 'Object'),
55
        ]);
56
    }
57
58
    private function ensureICanSeeBulkBillSearchBox()
59
    {
60
        $this->index->containsBulkButtons([
61
            'Delete',
62
        ]);
63
        $this->index->containsColumns([
64
            'Object',
65
            'Seller',
66
            'Buyer',
67
            'Tariff',
68
            'Time',
69
        ]);
70
    }
71
}
72