Code Duplication    Length = 15-18 lines in 2 locations

src/Context/FormstoneContext.php 1 location

@@ 59-73 (lines=15) @@
56
     * @param string          $field
57
     * @throws \Exception
58
     */
59
    private function openComponent(DocumentElement $page, $component, $field)
60
    {
61
        $select = $page->find('css', sprintf('#%s', $field));
62
        if (!$select) {
63
            throw new \Exception(sprintf('No select "%s" found', $field));
64
        }
65
66
        $fieldName = sprintf('.fs-%1$s .fs-%1$s-selected', $component);
67
        $choices   = $select->getParent()->find('css', $fieldName);
68
        if (!$choices) {
69
            throw new \Exception(sprintf('No field "%s" found', $field));
70
        }
71
72
        $choices->press();
73
    }
74
75
    /**
76
     * Select value in choice list

src/Context/Select2Context.php 1 location

@@ 98-115 (lines=18) @@
95
     * @param string          $field
96
     * @throws \Exception
97
     */
98
    private function openField(DocumentElement $page, $field)
99
    {
100
        // force select2 to be closed
101
        $page->find('css', 'body')->press();
102
103
        $fieldName = sprintf('select[name="%s"] + .select2-container', $field);
104
105
        $inputField = $page->find('css', $fieldName);
106
        if (!$inputField) {
107
            throw new \Exception(sprintf('No field "%s" found', $field));
108
        }
109
110
        $choice = $inputField->find('css', '.select2-selection');
111
        if (!$choice) {
112
            throw new \Exception(sprintf('No select2 choice found for "%s"', $field));
113
        }
114
        $choice->press();
115
    }
116
117
    /**
118
     * Fill Select2 search field