小编Sum*_*itk的帖子

用于模拟由新类对象调用的方法的单元测试

我正在为现有代码编写单元测试,就像这样

class someClass {
    public function __construct() { ... }

    public function someFoo($var) {
        ...
        $var = "something";
        ...
        $model = new someClass();
        model->someOtherFoo($var);
    }

    public someOtherFoo($var){
         // some code which has to be mocked
    }
}
Run Code Online (Sandbox Code Playgroud)

我应该如何模拟对函数" someOtherFoo" 的调用,使其some code在内部不执行" " someOtherFoo

class someClassTest {
   public function someFoo() {
      $fixture = $this->getMock('someClass ', array('someOtherFoo'));
      $var = "something";
      ....
      // How to mock the call to someOtherFoo() here
   }

}
Run Code Online (Sandbox Code Playgroud)

是否可以模拟构造函数,以便它返回我自己构造的函数或变量?

谢谢

php phpunit mocking

30
推荐指数
2
解决办法
2万
查看次数

排除pdepend,phpmd,phpcpd,phpcs,phpdoc,phploc中的某些目录和文件

在我的项目中有一些目录和某些PHP文件的大小非常大,因为我的构建失败了,我想将它们排除在我的 build.xml

问题1 -我是否必须为--ignore="path/filename"项目中的每个php文件编写?

Ques2-有些文件不是php,但.dat我也应该提一下这些文件--ignore吗?

问题3 -我可以指定根据文件大小排除文件,以便排除所有大于500kb的文件吗?

我当前的xml文件如下所示:

<?xml version="1.0" encoding="UTF-8"?>

<project name="name-of-project" default="build" basedir=".">
  <property name="root.dir" value="${basedir}/.."/>
  <property name="source" value="${root.dir}"/>

 <target name="clean"
         description="Clean up and create artifact directories">
  <delete dir="${basedir}/build/api"/>
  <delete dir="${basedir}/build/code-browser"/>
  <delete dir="${basedir}/build/coverage"/>
  <delete dir="${basedir}/build/logs"/>
  <delete dir="${basedir}/build/pdepend"/>

  <mkdir dir="${basedir}/build/api"/>
  <mkdir dir="${basedir}/build/code-browser"/>
  <mkdir dir="${basedir}/build/coverage"/>
  <mkdir dir="${basedir}/build/logs"/>
  <mkdir dir="${basedir}/build/pdepend"/>
 </target>

 <target name="phpunit"
         description="Run unit tests using PHPUnit and generates junit.xml and clover.xml">
  <exec executable="phpunit" failonerror="true">
    <env key="DOCUMENT_ROOT" value="${source}/api"/>
    <env key="MODEL_ROOT" value="${source}/model"/> …
Run Code Online (Sandbox Code Playgroud)

phpunit phpdoc php-codebrowser jenkins

18
推荐指数
1
解决办法
2万
查看次数

如何通过Jenkins运行phpunit测试时设置$ _SERVER ['']变量

我正在尝试为无法进行大量代码更改的应用程序编写单元测试.几乎所有代码库中的.php文件都使用了一些$ _SERVER ['']变量

require_once $_SERVER['DOCUMENT_ROOT'] . '/mainApi.php';
Run Code Online (Sandbox Code Playgroud)

所以现在当我必须编写并运行PHPUnit测试用例时,我必须以某种方式设置这些变量.目前我在用户环境中设置这些变量,然后进行

$_SERVER['DOCUMENT_ROOT'] = getenv('DOCUMENT_ROOT');
require_once $_SERVER['DOCUMENT_ROOT'] . '/mainApi.php';
Run Code Online (Sandbox Code Playgroud)

获取这样的服务器变量工作正常.我通过命令行运行我的测试$ phpunit test.php.

问题1:通过命令行运行phpunit测试时是否可以设置$ _SERVER变量?

我还必须通过Jenkins运行这些单元测试,我无法通过ANT/build文件设置这些服务器变量.

问题2:是否可以通过Jenkins中的ant构建文件设置这些变量,或者在通过Jenkins执行phpunit测试之前运行任何shell脚本?

我尝试通过shell脚本导出服务器变量

    export DOCUMENT_ROOT=/server/path-to-root-dir
Run Code Online (Sandbox Code Playgroud)

并在Jenkins的build.xml中调用该脚本

<export name="setEnv" description="set server var">
    <exec executable="sh">
       <arg value = "sumit.sh" />
    </exec> 
</target>
Run Code Online (Sandbox Code Playgroud)

但它不起作用.我可以为此做任何设置吗?谢谢!

php ant phpunit jenkins

13
推荐指数
1
解决办法
1万
查看次数

将Jenkins控制台输出作为HTML电子邮件发送

我不知道这是否可能,但仍然在这里询问是否有人尝试过/想过它.

我有一个构建运行,当失败回应出html代码,如下所示.我想将此html作为电子邮件发送给所有收件人.

目前,当我使用简单的电子邮件插件时,整个控制台输出将作为电子邮件发送,其中包含所有这些html标签(完全不可读).然后我安装了Email Ext插件,但我不确定预发送脚本是否可以读取我的控制台输出并发送电子邮件.有人试过吗?是值得花时间在它上面还是我应该修改输出以显示格式化文本?

此构建用于内部工具,我无法创建.html文件或将链接作为电子邮件发送到.html文件,因为路径位于防火墙后面.

我不知道这是否支持,但控制台输出是否可能显示html输出?

谢谢您的帮助!

                <style type="text/css">
                    table.gridtable {
                    font-family: verdana,arial,sans-serif;
                        font-size:11px;
                        color:#333333;
                        border-width: 1px;
                        border-color: #666666;
                        border-collapse: collapse;
                    }
                    table.gridtable th {
                    border-width: 1px;
                        padding: 8px;
                        border-style: solid;
                        border-color: #666666;
                        background-color: #dedede;
                    }
                    table.gridtable td {
                    border-width: 1px;
                        padding: 8px;
                        border-style: solid;
                        border-color: #666666;
                        background-color: #ffffff;
                    }
                </style>

                <table class="gridtable">
                    <thead>
                        <tr>
                          <th>Service Checked</th>
                          <th>Status</th>
                          <th>Response</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                          <td>canary</td>
                          <td>Success</td>
                          <td>Please override the check() method</td>
                        </tr>

                        <tr>
                          <td style="color: red;"><strong>www.mysite.com</strong></td>
                          <td style="color: red;">Failure</td>
                          <td>Ping to …
Run Code Online (Sandbox Code Playgroud)

html email build jenkins jenkins-plugins

10
推荐指数
3
解决办法
2万
查看次数

LinkedIn OAuth2.0为没有http或https的iOS应用重定向网址

我认为这可能是一个非常简单的设置问题,因为我对swift和LinkedIn API很新,我可能会这样做:

我正在使用swift创建一个iOS应用程序,并希望使用LinkedIn进行身份验证.为此,我在LinkedIn Developer Network上创建了一个应用程序.但现在我无法将我的应用重定向网址放在OAuth 2.0重定向网址中:

我的代码中的应用程序重定向URL看起来像oauth-testapp:// oauth-callback/linkedin,并且它在OAuth 1.0中正常工作,但对于OAuth 2.0,我需要以http://https://格式使用它.

这是我的困惑,因为我无法在OAuth 2.0重定向网址中添加我的网址oauth-testapp:// oauth-callback/linkedin :

在此输入图像描述

我看了一些帖子像这个这个,我不希望创建一个网站,将用户重定向到应用程序或创建应用程序内的Web视图.我的意思是我可以做到,但我只是想做一个POC,这就是我被封锁的地方.没有这些方法,它是否可能?有人用swift做过吗?非常感谢你的帮助!

oauth linkedin oauth-2.0 swift

6
推荐指数
1
解决办法
2597
查看次数

Jersey 客户端异步 POST 请求不等待响应

我创建了一个简单的 Jersey 客户端,它能够成功执行带有有效负载的 POST 请求。但现在它等待来自 http 端点的响应:

public void callEndpoint(String endpoint, String payload) {

    try {
        ClientConfig config = new DefaultClientConfig();
        Client client = Client.create(config);
        WebResource webResource = client.resource(getBaseURI(endpoint));

        log.debug("Sending payload [" + payload + "] to URL - [" + getBaseURI(endpoint) + "]");

        // POST method - Is this blocking?
        // Is it possible to not wait for response here
        ClientResponse response = webResource.accept("application/json")
                                             .type("application/json")
                                             .post(ClientResponse.class, payload);
        if (response.getStatus() != 200) {
            log.error("The endpoint [" + getBaseURI(endpoint) + "] …
Run Code Online (Sandbox Code Playgroud)

java post jersey google-http-client jersey-client

5
推荐指数
1
解决办法
9164
查看次数

通过ANT获取和使用父目录

我有一个像这样的目录结构和build.xml

    /path-to-project/src/prj1
    /path-to-project/src/prj2

    /path-to-project/tests
    /path-to-project/tests/build.xml
Run Code Online (Sandbox Code Playgroud)

我必须以某种方式得到路径

    /path-to-project/
Run Code Online (Sandbox Code Playgroud)

在我的build.xml中

我的build.xml是这样的

<project name="php-project-1" default="build" basedir=".">
  <property name="source" value="src"/>
    <target name="phploc" description="Generate phploc.csv">
      <exec executable="phploc">
        <arg value="--log-csv" />
        <arg value="${basedir}/build/logs/phploc.csv" />
        <arg path="${source}" />
      </exec>
    </target>
</project>
Run Code Online (Sandbox Code Playgroud)

在这里,我莫名其妙地想要得到的值${source}作为/path-to-project/src/,但我没有用得到它${parent.dir}

是否可以在build.xml中获取此路径?

php ant phpunit build.xml relative-path

4
推荐指数
2
解决办法
8409
查看次数

Spring amqp不向队列发布消息,而是向Exchange发布消息

我正在尝试使用多个队列测试和测试RabbitMQ的spring-amqp,因此我为每个队列创建了兔子模板并使用它来发送消息.发送的消息成功,我可以在交换机中看到一条消息,但我在队列中看不到任何内容.我猜这是非常小的设置,但无法弄明白.

这是我的applicationContext.xml

<bean id="banchmarkConnectionFactory" class="org.springframework.amqp.rabbit.connection.CachingConnectionFactory">
        <constructor-arg ref="benchmarkAmqpHost"/>
        <property name="username" ref="benchmarkAmqpUser"/>
        <property name="password" ref="benchmarkAmqpPass"/>
        <property name="virtualHost" ref="benchmarkAmqpVHost"/>
        <property name="channelCacheSize" value="10"/>
</bean>
<rabbit:template id="benchmarkAmqpTemplate"
        connection-factory="banchmarkConnectionFactory"
        exchange="my_exchange"
        queue="BenchmarkQueue"
        routing-key="BenchmarkQueue" />
<rabbit:admin connection-factory="banchmarkConnectionFactory"/>
<rabbit:queue name="BenchmarkQueue" auto-delete="true" durable="false" auto-declare="true"/>
Run Code Online (Sandbox Code Playgroud)

这是我使用benchmarkAmqpTemplate发布到队列的代码.

public class publishMessage {
    @Autowired
    private RabbitTemplate benchmarkAmqpTemplate;

    protected void publish(String payload) {
        benchmarkAmqpTemplate.setQueue("BenchmarkQueue");
        benchmarkAmqpTemplate.convertAndSend("my_exchange", "BenchmarkQueue", payload);

    }
}
Run Code Online (Sandbox Code Playgroud)

当我使用HelloWorld 示例时,它确实在队列中发布了一条消息,所以想知道我是否做错了什么. 更新 我能够通过direct-exchange在我的上下文xml中添加标记来解决这个问题.我的完整xml看起来像这样:

    <beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:rabbit="http://www.springframework.org/schema/rabbit"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsdhttp://www.springframework.org/schema/rabbit http://www.springframework.org/schema/rabbit/spring-rabbit.xsd">

<bean id="banchmarkConnectionFactory" class="org.springframework.amqp.rabbit.connection.CachingConnectionFactory">
            <constructor-arg ref="benchmarkAmqpHost"/>
            <property name="username" ref="benchmarkAmqpUser"/>
            <property name="password" …
Run Code Online (Sandbox Code Playgroud)

spring rabbitmq spring-rabbit spring-amqp spring-boot

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

Python - 从不同包中的一个包创建类的对象

几天前我开始使用Python,我想我有一个非常基本的问题,我被卡住了.也许我没有在Python中正确地做到这一点,所以需要专家的一些建议:

我在一个包lib中有一个config.cfg和一个类测试,如下所示:

的Myproj/LIB /则pkg1 /的config.cfg

[api_config]
url = https://someapi.com/v1/
username=sumitk
Run Code Online (Sandbox Code Playgroud)

的Myproj/LIB /则pkg1/test.py

class test(object):

    def __init__(self, **kwargs):

        config = ConfigParser.ConfigParser()
        config.read('config.cfg')
        print config.get('api_config', 'username') 
          #just printing here but will be using this as a class variable

    def some other foos()..
Run Code Online (Sandbox Code Playgroud)

现在我想在另一个包中的其他模块中创建一个测试对象

的Myproj /示例/ useTest.py

from lib.pkg1.test import test

def temp(a, b, c):
    var = test()

def main():
    temp("","","")

if __name__ == '__main__':
    main()
Run Code Online (Sandbox Code Playgroud)

运行useTest.py给我错误:

...
print config.get('api_config', 'username')
File "C:\Python27\lib\ConfigParser.py", line 607, in get
     raise NoSectionError(section)
ConfigParser.NoSectionError: No section: 'api_config' …
Run Code Online (Sandbox Code Playgroud)

python ironpython python-2.7 python-3.x

2
推荐指数
1
解决办法
266
查看次数