【问题标题】:How do I run a shell command from inside a Behat test?如何从 Behat 测试中运行 shell 命令?
【发布时间】:2015-05-06 22:05:25
【问题描述】:

我正在开发 laravel 5 应用程序,我需要创建一个工匠命令。我使用 Behat 作为我的测试框架。我知道我可以在 behat 中测试我的数据库的状态。我想运行类似“的命令”

php artisan my:command

从一个行为步骤中。我怎样才能做到这一点?

谢谢

【问题讨论】:

    标签: laravel behat laravel-artisan


    【解决方案1】:

    在您的FeatureContext 类中:

    /**
     * @When I run :command
     */
    public function iRun($command)
    {
        $this->output = shell_exec($command);
    }
    

    如果您使用 Symfony 控制台组件,请查看https://gist.github.com/tPl0ch/6706427

    您甚至可以在https://gist.github.com/everzet/1683634 上描述您的命令。

    【讨论】:

    【解决方案2】:

    我找到了一个简单的方法来做到这一点。由于我正在运行 artisan 命令,因此我可以使用 Artisan 外观。

    /**
         * @Given I run the artisan command :command with args :args
         * @param $command
         * @param $args
         */
        public function iRunTheArtisanCommandWithArgs($command, $args)
        {
            \Artisan::call($command, [$args]);
        }
    

    【讨论】:

      猜你喜欢
      • 2016-12-23
      • 2014-09-02
      • 2015-05-22
      • 2016-02-03
      • 1970-01-01
      • 1970-01-01
      • 2016-10-13
      • 2015-05-09
      • 2011-04-25
      相关资源
      最近更新 更多