function it_is_initializable() { if (Unix::isUnix()) { //Currently this will work only on *nix $this->shouldHaveType('Hexmedia\\Crontab\\Writer\\SystemWriter'); } }
function it_is_able_to_create_writer(Crontab $crontab) { $this->isSystemSupported(); $created = $this::create($crontab); $created->shouldImplement('Hexmedia\\Crontab\\Writer\\System\\WriterInterface'); if (true === Unix::isUnix()) { $created->shouldImplement('Hexmedia\\Crontab\\Writer\\System\\UnixWriter'); } }
function it_is_throwing_when_there_is_no_parser() { $wasUnix = false; if (true === Unix::isUnix()) { $wasUnix = true; Unix::removeUnix(PHP_OS); } $this->clearParser()->shouldReturn($this); $this->getParsers()->shouldHaveCount(0); $this->shouldThrow(new NoSupportedParserException(sprintf('There is no supported parser for this type or operating system (your is "%s").', PHP_OS)))->duringCreate('some text', '/tmp/file'); if ($wasUnix) { Unix::addUnix(PHP_OS); } }
/** * @return string * * @SuppressWarnings(PHPMD.StaticAccess) */ protected function getContent() { $result = Unix::get($this->user); return $result; }
/** * @return bool * * @SuppressWarnings(PHPMD.StaticAccess) */ public static function isSupported() { return Unix::isUnix(); }
protected function isSystemSupported() { if (false === Unix::isUnix()) { throw new SkippingException(sprintf('Your os "%s" is currently not supported.', PHP_OS)); } }
function it_allows_to_write($crontab) { $processBuilder = new FakeProcessBuilder(); $shouldBe = $this->defaultContent; $processBuilder->addCommand("'crontab' '(/var)?/tmp/.*'", function ($command) use($shouldBe) { if (preg_match("#'crontab' '((/var)?/tmp/.*)'#", $command, $matches)) { $content = file_get_contents($matches[1]); if ($content !== $shouldBe) { throw new FailureException("Content in not correct"); } } }, 1); Unix::setProcessBuilder($processBuilder); $this->write($crontab)->shouldReturn(true); Unix::setProcessBuilder(null); }
/** * @param string $content * * @return bool * * @SuppressWarnings(PHPMD.StaticAccess) */ protected function saveCrontab($content) { Unix::save($content); return true; }
/** * @Given The process builder is fake * * @SuppressWarnings(PHPMD.StaticAccess) */ public function theProcessBuilderIsFake() { $this->processBuilder = new FakeProcessBuilder(); Unix::setProcessBuilder($this->processBuilder); }