小编Jul*_*tré的帖子

从composer script/composer API获取包安装路径

从Composer安装此软件包后,我想复制一个位于软件包内的文件.

实际上,我希望在安装或更新Composer中的软件包后,将一些可能位于下载软件包中的文件复制到另一个目录中.我使用脚本,使用post-package-install和post-package-update命令,但是我找不到如何获取安装路径.

这是我目前的脚本:

use Composer\Script\PackageEvent;

class MyScript {

public static function copyFiles(PackageEvent $event)
{
    $package = $event->getOperation()->getPackage();

    $originDir = $package->someFunctionToFind(); #Here, I should retrieve the install dir

    if (file_exists($originDir) && is_dir($originDir)) {
        //copy files from $originDir to a new location
    } 

}
}
Run Code Online (Sandbox Code Playgroud)

有谁知道如何从PackageEvent类(参数中提供)获取已安装/更新的软件包的安装目录?

注意 :

我尝试$event->getOperation()->getPackage->targetDir()但是这不提供安装路径,而是提供在composer.json中定义的包targetDir

composer-php

4
推荐指数
1
解决办法
2280
查看次数

使用Symfony DomCrawler在选择输入中选择不可能的值

如果我select在表单输入中发送错误的值,我想测试我的应用程序的行为.

这是我在HTML中的表单:

<form (...)>
   (...)
<select name="select_input">
     <option value="1">text</option>
</select>

</select>
Run Code Online (Sandbox Code Playgroud)

在我的测试中,在使用爬虫获取表单并尝试"选择"不正确的值:

$form['select_input'] = 9999999;
$client->submit($form);
/* EDIT */
/*I am expecting the user to not be redirected to the user page,
  and the server to respond with the same form, containing an error message */
$this->assertFalse($client->getResponse()->isRedirect('/success_page'));
$this->assertEquals(1, $client->getCrawler()->filter('input.error'));
Run Code Online (Sandbox Code Playgroud)

但在控制台中,我收到消息:

InvalidArgumentException: Input "user_profile[voteProfile]" cannot take "9999999" as a value (possible values: 1)
Run Code Online (Sandbox Code Playgroud)

如何选择不正确的值来测试答案?真实服务器可能会发送错误的值.

php phpunit symfony

3
推荐指数
1
解决办法
1229
查看次数

标签 统计

composer-php ×1

php ×1

phpunit ×1

symfony ×1