小编eis*_*eis的帖子

用PHP测试.如何确保正确运行?

首先,我不知道它是否被称为单元测试.如果它有不同的名称,请随时纠正我.

我正在开发像这样的Web应用程序.

假设我正在开发一个表单来将值保存到数据库中.我开发HTML和PHP.我有时间在浏览器中按F5并检查HTML/jQuery是否没有错误,PHP不会出现错误的分号等错误.

当它完成并且一切都准备好进行测试时,我开始测试我的代码的一小部分.喜欢;

  1. -Do $ _POST数组是否正确地从表单文件中获取值?(我用print_r测试)
  2. - "$ email"变量是否正确清理为有效的电子邮件?(我用不同的能力测试它,例如:aaa @ bbb,aa @ bb.com,@@ b.net等)
  3. - 提交的表单是否通过了所有控件,并成功插入到数据库中?(我查看我的MySQL表.)
  4. - 表单是否正确显示错误/成功消息?
  5. -...等等.

如果它使用正确的值,并且失败并返回错误的值; 我相信表单按预期工作,没有错误,所以我转向其他事情.

而不是这样做,我想确保事情完美无缺,否则在没有垃圾邮件F5浏览器的情况下通知我这个问题.

像这样;

<?php
/* Unit Testing Start --
-ensure: isset($_POST['submit']) returns TRUE;
-ensure: isset($email) returns TRUE;
-ensure: isValidEmail($email) returns TRUE;
-ensure: connectDatabase() returns TRUE;
-ensure: getMysqlAffectedRows() returns 1;
-ensure: hasErrors() returns false;
*/

?>
Run Code Online (Sandbox Code Playgroud)

我的表单代码使用我上面发布的功能.

当它运行时,它应该向我显示如下消息:(最好还记录它)

Test complete. Tested (6) possibilities, (4) succeeded, (2) failed. 
Failed 1: isValidEmail() returned FALSE, expected: TRUE. 
Failed 2: getMysqlAffectedRows returned NULL/0, expected …
Run Code Online (Sandbox Code Playgroud)

php testing automated-tests

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

访问被拒绝:http://repo.maven.apache.org/maven2/commons-codec/commons-codec/1.4/commons-codec-1.4.pom,ReasonPhrase:Forbidden

我试图构建 Maven 项目,

每当我在命令行上运行“mvn clean install”时,都会出现以下错误:

无法解析项目 com.my_project:jar:0.0.1-SNAPSHOT 的依赖项:无法收集 [com.datastax.cassandra:cassandra-driver-core:jar:3.0.1 (compile), org.apache.kafka 的依赖项:kafka-clients:jar:0.9.0.1(编译)、org.apache.kafka:kafka_2.10:jar:0.9.0.1(编译)、com.thinkaurelius.titan:titan-core:jar:1.0.0(编译) ), com.tinkerpop.blueprints:blueprints-core:jar:2.6.0 (编译), com.thinkaurelius.titan:titan-cassandra:jar:1.0.0 (编译), com.thinkaurelius.titan:titan-all: jar:1.0.0(编译)、org.aspectj:aspectjrt:jar:1.6.5(编译)、com.jayway.awaitility:awaitility:jar:1.6.5(编译)、junit:junit:jar:4.11(测试)]:无法读取 commons-codec:commons-codec:jar:1.4 的工件描述符:无法从/向中央传输工件 commons-codec:commons-codec:pom:1.4 (http://repo.maven.apache.org/maven2):拒绝访问:http : //repo.maven.apache.org/maven2/commons-codec/commons-codec/1.4/commons-codec-1.4.pom , 理由:禁止。-> [帮助 1]

请帮助我,我是 JAVA 世界的新手。

这是我拒绝访问的某种代理设置吗?

maven

6
推荐指数
2
解决办法
8063
查看次数

如何让maven警告转换依赖版本不匹配?

在下面的示例Maven依赖项中,slf4j依赖项想要引入log4j 1.2.17并且log4j显式依赖项想要引入1.2.15.Maven将log4j解析为版本1.2.15但是,没有警告Maven打印出sl4j想要更高版本的log4j.

我怎样才能让Maven警告这些类型的冲突,而不是默默地采用1.2.15版本?

<dependency>
  <groupId>org.slf4j</groupId>
  <artifactId>slf4j-log4j12</artifactId>
  <version>1.7.2</version>
</dependency>
<dependency>
  <groupId>log4j</groupId>
  <artifactId>log4j</artifactId>
  <version>1.2.15</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)

maven-3 maven

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

为什么我们需要function_exists?

为什么我们需要检查 function_exists 是否存在用户定义的函数?对于内部或核心 PHP 函数来说,看起来没问题,但如果用户知道并自己定义了一个函数,那么为什么需要检查它是否存在呢?

以下是自定义用户定义的函数

if( !function_exists( 'bia_register_menu' ) ) {
    function bia_register_menu() {
        register_nav_menu('primary-menu', __('Primary Menu'));
    }
    add_action('init', 'bia_register_menu');
}
Run Code Online (Sandbox Code Playgroud)

谢谢

php wordpress

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

如何在Rails上将响应主体打印到stdout/stderr

我想打印出我的应用程序生成的响应体到stdout/stderr进行调试.流量是服务器 - 服务器,因此我无法使用客户端工具来获取http流量.

puts @response.bodyhttp://api.rubyonrails.org/classes/ActionDispatch/Response.html中提到了,但在我的app控制器中@response是未定义的.有没有办法让我在我的rails应用程序中打印响应正文到日志,如果有,怎么样?


基于给出的答案,它是这样的:

after_filter :print_response_body, :only => [:index]

def print_response_body 
  $stderr.puts response.body
end
Run Code Online (Sandbox Code Playgroud)

debugging ruby-on-rails

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

在WLS 12中部署应用程序时出现java.lang.ArrayIndexOutOfBoundsException

我在Weblogic中部署应用程序时遇到此错误.

   <Oct 3, 2013 12:18:00 PM IST> <Error> <Deployer> <BEA-149205> <Failed to initialize the application "MyApp" due to error java.lang.ArrayIndexOutOfBoundsException: 4818
8
java.lang.ArrayIndexOutOfBoundsException: 48188
        at com.bea.objectweb.asm.ClassReader.readClass(Unknown Source)
        at com.bea.objectweb.asm.ClassReader.accept(Unknown Source)
        at com.bea.objectweb.asm.ClassReader.accept(Unknown Source)
        at weblogic.application.utils.annotation.ClassInfoImpl.<init>(ClassInfoImpl.java:45)
        at weblogic.application.utils.annotation.ClassfinderClassInfos.polulateOneClassInfo(ClassfinderClassInfos.java:145)
        Truncated. see log file for complete stacktrace
Caused By: java.lang.ArrayIndexOutOfBoundsException: 48188
        at com.bea.objectweb.asm.ClassReader.readClass(Unknown Source)
        at com.bea.objectweb.asm.ClassReader.accept(Unknown Source)
        at com.bea.objectweb.asm.ClassReader.accept(Unknown Source)
        at weblogic.application.utils.annotation.ClassInfoImpl.<init>(ClassInfoImpl.java:45)
        at weblogic.application.utils.annotation.ClassfinderClassInfos.polulateOneClassInfo(ClassfinderClassInfos.java:145)
        Truncated. see log file for complete stacktrace
>
Run Code Online (Sandbox Code Playgroud)

I understand that this is because of an class not getting …

java weblogic

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

Str_pad无法正常工作

    **PHP**

    $datearr = explode("/", $cutOff);
    $month = $datearr[0];
    $day = $datearr[1];
    $year = $datearr[2];
    $mainten = "MAINTENANCE";
    $pad='&nbsp;';
    $maint = str_pad($mainten, 20, $pad);
    $string = $cduid . $maint . $inarea . $year . $month . $day . "\n";
Run Code Online (Sandbox Code Playgroud)

我试图将此字符串解析为服务器,并且$ maint必须用右边的空格填充.我也试过.....

    $datearr = explode("/", $cutOff);
    $month = $datearr[0];
    $day = $datearr[1];
    $year = $datearr[2];
    $mainten = "MAINTENANCE";
    $maint = str_pad($mainten, 20);
    $string = $cduid . $maint . $inarea . $year . $month . $day . "\n";
Run Code Online (Sandbox Code Playgroud)

当我回显$ string $ maint时,右边只有1个空格.如果我替换$ pad …

php

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

如何使用XML和Java配置实现Spring Security 4

我正在尝试将Spring-Security 4实现到我的Spring MVC web和rest app中.我添加了2个类来启用Spring安全性的java配置方式.我仍然希望保留我的web.xml而不是将整个项目更改为使用java配置.一旦我这样做,我收到以下错误:

29-May-2015 08:47:12.826 SEVERE [localhost-startStop-1]  
org.apache.catalina.core.StandardContext.filterStart Exception starting   
filter springSecurityFilterChain
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean   
named 'springSecurityFilterChain' is defined
at org.springframework.beans.factory.support.DefaultListableBeanFactory.
getBeanDefinition(DefaultListableBeanFactory.java:687)
Run Code Online (Sandbox Code Playgroud)

如您所见,它表示无法识别springSecurityFilterChain.这当然应该由@EnableWebSecurity启用,如下所示:

用于Spring Security的类:

@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
  auth.inMemoryAuthentication().withUser("abc").password("123456").roles("USER");
  auth.inMemoryAuthentication().withUser("admin").password("123456").roles("ADMIN");
  auth.inMemoryAuthentication().withUser("dba").password("123456").roles("DBA");
}

@Override
protected void configure(HttpSecurity http) throws Exception {

  http.authorizeRequests()
    .antMatchers("/admin/**").access("hasRole('ROLE_ADMIN')")
    .antMatchers("/dba/**").access("hasRole('ROLE_ADMIN') or hasRole('ROLE_DBA')")
    .and().formLogin();

    }
}

public class SpringSecurityInitializer extends AbstractSecurityWebApplicationInitializer {
   //do nothing
}
Run Code Online (Sandbox Code Playgroud)

奇怪的是,如果我将springSecurityFilterChain添加到我的web.xml,在运行时它会抱怨并说有一个重复的springSecurityFilterChain.我注意到最终在Java配置中,他们这样做:

public class MvcWebApplicationInitializer extends
    AbstractAnnotationConfigDispatcherServletInitializer {

@Override …
Run Code Online (Sandbox Code Playgroud)

spring-mvc spring-security spring-restcontroller

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

如何使用注释配置PayloadValidatingInterceptor

我正在尝试开发Spring Web服务并遵循本教程https://spring.io/guides/gs/production-web-service/

项目结构(和配置类名称)与本教程中提到的相同。我正在尝试使用注释进行所有可能的配置,并希望避免所有基于xml的配置。到目前为止,我什至通过使用Java配置避免了applicationContext.xml和web.xml。但是,现在,我想介绍本教程中所示的XSD验证:http : //stack-over-flow.blogspot.com/2012/03/spring-ws-schema-validation-using.html,即通过扩展PayloadValidatingInterceptor类如本教程所示,此自定义验证器拦截器随后需要使用以下xml配置进行注册:

<bean class="org.springframework.ws.server.endpoint.mapping.PayloadRootAnnotationMethodEndpointMapping">
 <property name="interceptors">
  <list>
    <ref bean="validatingInterceptor"/>   
  </list>
 </property>
</bean>

<bean id="validatingInterceptor" class="com.test.ValidationInterceptor ">
     <property name="schema" value="/jaxb/test.xsd"/>
</bean>
Run Code Online (Sandbox Code Playgroud)

但是,我不起诉如何使用注释进行上述配置。即将XSD文件设置为拦截器。我尝试覆盖WsConfigurerAdaptor类的“ addInterceptor”以注册拦截器。请让我知道是否需要这样做,或者使用批注完成整件事的正确方法是什么。

spring spring-ws spring-boot

5
推荐指数
2
解决办法
3493
查看次数

Apache SSL 使用 openssl 将 itermediateCA.cer 转换为 crt

尝试将 IntermidiateCA.cer 转换为 Apache 的 crt 格式,但我做不到。我使用下面的命令:

openssl x509 -inform DER -in IntermediateCA.cer -out IntermediateCA.crt
Run Code Online (Sandbox Code Playgroud)

这是我在下面遇到的错误

unable to load certificate
4276141236:error:0D0680A8:asn1 encoding routines:ASN1_CHECK_TLEN:wrong 
tag:tasn_dec.c:1198:
 4276141236:error:0D07803A:asn1 encoding routines:ASN1_ITEM_EX_D2I:nested 
asn1 error:tasn_dec.c:372:Type=X509
Run Code Online (Sandbox Code Playgroud)

请注意服务器是solaris 5.10

apache ssl openssl

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