protected function writeToHandle($handleName, $data) { if ($handleName == 'export' && $data == $this->number . "\n") { $this->enabled = true; $this->handleData['direction'] = Pin::DIRECTION_IN; $this->handleData['edge'] = Pin::EDGE_NONE; $this->handleData['value'] = '0'; } elseif ($handleName == 'unexport' && $data == $this->number . "\n") { $this->enabled = false; } else { $this->handleData[$handleName] = $data; } if ($this->emulator !== null) { $this->emulator->reportFileWrite($this, $handleName, $data); } }
/** * @test */ public function testAssert() { $emulator = new Emulator(); $emulator->setAssertMask(Emulator::ACTION_CHANGE_VALUE); $pin1 = $emulator->createPin(1); $pin1->enable(); $pin1->setDirection(Pin::DIRECTION_OUT); $emulator->assert([[1, Emulator::ACTION_CHANGE_VALUE, true], [1, Emulator::ACTION_CHANGE_VALUE, false], [1, Emulator::ACTION_CHANGE_VALUE, true]]); $pin1->setValue(true); $pin1->setValue(false); $pin1->setValue(true); // Verify ASSERT_IGNORE_MISSING works with empty assert list $emulator->setAssertMode(Emulator::ASSERT_IGNORE_MISSING); $pin1->setValue(true); // Verify ASSERT_FAIL_MISSING throws on empty assert list $emulator->setAssertMode(Emulator::ASSERT_FAIL_MISSING); try { $pin1->setValue(true); $this->fail('ASSERT_FAIL_MISSING not working!'); } catch (Exception $e) { } // Fail an assert $emulator->assert([[1, Emulator::ACTION_CHANGE_VALUE, true]]); try { $pin1->setValue(false); $this->fail('Faulty assertion was ignored!'); } catch (Exception $e) { $emulator->assert([]); } // Verify ASSERT_FAIL_EXCESS throws on remaining expected actions $emulator2 = clone $emulator; $emulator2->setAssertMode(Emulator::ASSERT_FAIL_EXCESS); $emulator2->assert([[1, Emulator::ACTION_CHANGE_VALUE, true]]); try { unset($emulator2); $this->fail('ASSERT_FAIL_EXCESS not working!'); } catch (Exception $e) { } // Verify ASSERT_IGNORE_EXCESS works $emulator->setAssertMode(Emulator::ASSERT_IGNORE_EXCESS); $emulator->assert([[1, Emulator::ACTION_CHANGE_VALUE, true]]); unset($emulator); }