GVKun编程网logo

如何从代码运行phpunit?(php怎么实现代码运行功能)

15

最近很多小伙伴都在问如何从代码运行phpunit?和php怎么实现代码运行功能这两个问题,那么本篇文章就来给大家详细解答一下,同时本文还将给你拓展bash–wp-cli:无法在MAMP上运行phpun

最近很多小伙伴都在问如何从代码运行phpunit?php怎么实现代码运行功能这两个问题,那么本篇文章就来给大家详细解答一下,同时本文还将给你拓展bash – wp-cli:无法在MAMP上运行phpunit、c# – 从代码运行Sitecore Powershell脚本、cakephp – 如何从phpunit覆盖率报告中排除目录、phpstorm配置phpunit,进行php单元测试等相关知识,下面开始了哦!

本文目录一览:

如何从代码运行phpunit?(php怎么实现代码运行功能)

如何从代码运行phpunit?(php怎么实现代码运行功能)

我想使用 PHPUnit的本地安装(通过composer)来运行我的测试并在屏幕上显示它(例如acessing / admin / tests).但是,我在文档中找到的运行测试的唯一方法是使用命令行工具.

贝娄是我正在寻找的一个假设的例子:

$session = new PHPUnit_TestSession('path/to/folder');
$results = $session->runAll();
echo $results->failuresCount();
// other hipotetical $result->methods...
// maybe $results->dump()

解决方法

这可能是一种矫枉过正,但你有所待遇: https://github.com/NSinopoli/VisualPHPUnit

总结

以上是小编为你收集整理的如何从代码运行phpunit?全部内容。

如果觉得小编网站内容还不错,欢迎将小编网站推荐给好友。

bash – wp-cli:无法在MAMP上运行phpunit

bash – wp-cli:无法在MAMP上运行phpunit

我跟着 plugin test setup/install instructions.我得到了wp脚本插件测试我的插件来运行.但是在下一步当我尝试运行bash bin / install-wp-tests.sh wordpress_test root”localhost最新我收到以下错误:
MysqLadmin: connect to server at 'localhost' Failed
error: 'Can't connect to MysqL server on 'localhost' (61)'
Check that MysqLd is running on localhost and that the port is 3306.
You can check this by doing 'telnet localhost 3306'

我的本地WordPress网站正在运行MAMP(正在工作).我不知道这是否与安装脚本相关,因为我认为它正在创建一个临时数据库来运行测试…如果它使用内置的OSX或MysqL的MysqL?

这是wp –info的输出

$./vendor/wp-cli/wp-cli/bin/wp --info
PHP binary: /Applications/MAMP/bin/PHP/PHP5.6.10/bin/PHP
PHP version:    5.6.10
PHP.ini used:   /Applications/MAMP/bin/PHP/PHP5.6.10/conf/PHP.ini
WP-CLI root dir:    /Applications/MAMP/htdocs/pipeline/wp-content/plugins/wp-github-pipeline/vendor/wp-cli/wp-cli
WP-CLI global config:   
WP-CLI project config:  
WP-CLI version: 0.19.2

更新2
我发现原来MysqL没有安装…这就是为什么我无法连接!但现在是.我运行安装脚本,这是工作…

$./vendor/wp-cli/wp-cli/bin/wp db tables
wp_users
wp_userMeta
wp_posts
wp_comments
wp_links
wp_options
wp_postMeta
wp_terms
wp_term_taxonomy
wp_term_relationships
wp_commentMeta

但是当我运行PHPunit我得到这个:

$PHPunit
PHP Warning:  MysqLi_real_connect(): (HY000/2002): No such file or directory in /private/tmp/wordpress/wp-includes/wp-db.PHP on line 1452
PHP Stack trace:
PHP   1. {main}() /private/tmp/wordpress-tests-lib/includes/install.PHP:0
PHP   2. require_once() /private/tmp/wordpress-tests-lib/includes/install.PHP:21
PHP   3. require_wp_db() /private/tmp/wordpress/wp-settings.PHP:79
PHP   4. wpdb->__construct() /private/tmp/wordpress/wp-includes/load.PHP:350
PHP   5. wpdb->db_connect() /private/tmp/wordpress/wp-includes/wp-db.PHP:649
PHP   6. MysqLi_real_connect() /private/tmp/wordpress/wp-includes/wp-db.PHP:1452

Warning: MysqLi_real_connect(): (HY000/2002): No such file or directory in /private/tmp/wordpress/wp-includes/wp-db.PHP on line 1452

我的问题的一部分是,我不清楚是否wp-cli应该完全运行在native(cli)PHP / MysqL或MAMP的PHP / MysqL,或两者的某种组合.

更新4
我确定最后的问题是PHPunit需要安装在MAMP中,但是我正在从OSX运行…

$which PHPunit
/usr/bin/PHPunit

在this gist提到.

更新6

原来你不能再使用梨来安装PHPunit了.所以我把它作为一个作曲家依赖在require-dev,但是当我运行那个版本我得到相同的错误!

$./vendor/PHPunit/PHPunit/PHPunit
PHP Warning:  MysqLi_real_connect(): (HY000/1045): Access denied for user 'root'@'localhost' (using password: NO) in /private/tmp/wordpress/wp-includes/wp-db.PHP on line 1452
PHP Stack trace:
PHP   1. {main}() /private/tmp/wordpress-tests-lib/includes/install.PHP:0
PHP   2. require_once() /private/tmp/wordpress-tests-lib/includes/install.PHP:21
PHP   3. require_wp_db() /private/tmp/wordpress/wp-settings.PHP:79
PHP   4. wpdb->__construct() /private/tmp/wordpress/wp-includes/load.PHP:350
PHP   5. wpdb->db_connect() /private/tmp/wordpress/wp-includes/wp-db.PHP:649
PHP   6. MysqLi_real_connect() /private/tmp/wordpress/wp-includes/wp-db.PHP:1452

Warning: MysqLi_real_connect(): (HY000/1045): Access denied for user 'root'@'localhost' (using password: NO) in /private/tmp/wordpress/wp-includes/wp-db.PHP on line 1452

我甚至把它添加到我的路上,以确保…

$which PHPunit
/Applications/MAMP/htdocs/pipeline/wp-content/plugins/wp-github-pipeline/vendor/PHPunit/PHPunit/PHPunit

更新7

阅读this博客文章底部的评论后,我看到安装脚本引用了OSX版本的MysqLadmin.我不知道这是否重要,但我在路径中添加了MAMPs版本,并重新运行安装脚本.似乎在/ tmp / anyway中安装wordpress文件.运行PHPunit时出现同样的错误

如果您使用MAMP,问题可能与您的MysqL服务器设置相关.确保在MAMP设置中选中允许网络访问选项:

更新1

在根目录中创建PHPinfo.PHP文件(通常是/ Applications / MAMP / htdocs for MAMP).粘贴以下内容:

<?PHP PHPinfo() ?>

然后检查加载的配置文件属性.在终端中使用nano或其他文本编辑器打开它.然后找到并将此3 propertiespdo_MysqL.default_socket,MysqL.default_socket,MysqLi.default_socket更改为您的套接字文件.

参考http://maccrazy.com/lion-upgrade-killed-my-php-site-and-how-i-fixed-it

c# – 从代码运行Sitecore Powershell脚本

c# – 从代码运行Sitecore Powershell脚本

我已经安装了流行的 Powershell Console Sitecore插件,到目前为止我很喜欢它.

我希望能够以编程方式在C#中调用特定脚本(因为用户输入的结果),但我找不到任何有效的资源指向我正确的方向.

有没有办法实现这个目标?经典Powershell脚本的规则是否适用于Sitecore版本?

解决方法

您可以使用以下代码直接从您自己的代码中调用任何PowerShell脚本

using Cognifide.PowerShell.Core.Host;
using Sitecore.Data.Items;

namespace MyProject
{
    public class TestSPE
    {
        public void Invoke()
        {
            using (ScriptSession scriptSession = ScriptSessionManager.NewSession("Default",true))
            {
                Item speScriptItem = Sitecore.Context.Database.GetItem("/path-or-id/to-spe-item");
                string script = speScriptItem["Script"];
                if (!string.IsNullOrEmpty(script))
                    scriptSession.ExecuteScriptPart(script);
            }
        }
    }
}

请务必在项目中添加对Cognifide.PowerShell.dll的引用.

如果您的脚本未存储在Sitecore中的PowerShell脚本项目上,则传入一个包含您希望运行的SPE命令和脚本的字符串.

您可以在此博客文章中阅读有关Using PowerShell Console for Sitecore in Your Own Code的更多信息

更新:

要创建“脚本项”,请使用以下模板创建项:

/sitecore/templates/Modules/PowerShell Console/PowerShell Script

这将为您提供脚本正文,您可以在其中放置代码.您可以在/ sitecore / system / Modules / PowerShell / Script Library下的模块脚本库中找到默认SPE脚本的示例.

更新2:

要从脚本中获取返回值,请调用以对方法的stringOutput参数传递false:

List<object> results; 
results = scriptSession.ExecuteScriptPart(script,false);

cakephp – 如何从phpunit覆盖率报告中排除目录

cakephp – 如何从phpunit覆盖率报告中排除目录

我在写信-
<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
      <testsuite name="My Test Suite">
         <directory suffix=".PHP">Test/Case/Model</directory>
        <exclude>Test/Case/Model/Behavior</exclude>
      </testsuite>
    </testsuites>

但它不排除覆盖率报告中的行为.如何从覆盖率报告中排除此目录或文件?

<?xml version="1.0" encoding="utf-8"?>
<PHPunit>
  <filter>
    <whitelist>
      <directory suffix=".PHP">../</directory>
      <exclude>
        <file>../ext_emconf.PHP</file>
        <directory suffix=".PHP">../tests</directory>
      </exclude>
    </whitelist>
  </filter>
</PHPunit>

phpstorm配置phpunit,进行php单元测试

phpstorm配置phpunit,进行php单元测试

phpstorm配置phpunit,进行php接口单元测试

1。安装php5.6,phpunit5.1,curl

mac 自带的默认是php5.5,需要升级,打开终端,运行:
curl -s http://php-osx.liip.ch/install.sh | bash -s 5.6

查看phpunit官网文档,根据文档步骤

wget https://phar.phpunit.de/phpunit.phar$ chmod +x phpunit.phar$ sudo mv phpunit.phar /usr/local/bin/phpunit
$ phpunit --version
PHPUnit 5.1.3 by Sebastian Bergmann and contributors
登录后复制

2。下载phpunit.phar文件,然后在phpstorm 中加载,如图

立即学习“PHP免费学习笔记(深入)”;

phpstorm配置phpunit,进行php单元测试

第二个就是phpunit.phar的路径
phpstorm配置phpunit,进行php单元测试

3.。加载phpunit安装目录:

phpstorm配置phpunit,进行php单元测试

4.。选择编译器

phpstorm配置phpunit,进行php单元测试

5,根据curl 模拟访问接口,

&#39;).addClass(&#39;pre-numbering&#39;).hide(); $(this).addClass(&#39;has-numbering&#39;).parent().append($numbering); for (i = 1; i <= lines; i++) { $numbering.append($(&#39;
&#39;).text(i)); }; $numbering.fadeIn(1700); }); });
登录后复制

以上就介绍了phpstorm配置phpunit,进行php单元测试,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助

今天的关于如何从代码运行phpunit?php怎么实现代码运行功能的分享已经结束,谢谢您的关注,如果想了解更多关于bash – wp-cli:无法在MAMP上运行phpunit、c# – 从代码运行Sitecore Powershell脚本、cakephp – 如何从phpunit覆盖率报告中排除目录、phpstorm配置phpunit,进行php单元测试的相关知识,请在本站进行查询。

本文标签: