小编Mic*_*rgl的帖子

使用Symfony测试数据库插入

今天是个好日子,

在过去的几天里,我一直在研究测试驱动开发,并决定我也需要学习它.虽然我无法弄清楚如何准确地做到这一点.

我的项目依赖于Symfony2.1.6框架和Doctrine,所以我有一些需要填充的数据库表.

书(1,n) - (0,n)类型

现在,如果我想插入一个类型记录,我首先需要编写一个测试来确保所有内容都被插入(或者我错了吗?)

现在的问题是我不知道如何访问我的数据库,因为它是由框架管理的.

我唯一能找到的是使用LiipFunctionalTestBundle https://github.com/liip/LiipFunctionalTestBundle,它每次运行测试时都会创建并恢复临时数据库.我按照说明设置了所有内容.

编辑:我的app/config/config_test.yml现在看起来像这样:

imports:
    - { resource: config_dev.yml }

framework:
    test: ~
    session:
        storage_id: session.storage.filesystem

liip_functional_test: ~

web_profiler:
    toolbar: false
    intercept_redirects: false

swiftmailer:
    disable_delivery: true

liip_functional_test:
    cache_sqlite_db: true

doctrine:
    dbal:
        default_connection: default
        connections:
            default:
                driver:   pdo_sqlite
                path:     %kernel.cache_dir%/test.db
Run Code Online (Sandbox Code Playgroud)

所以现在我有一个GenreTest类:
Liip没有文档所以我只是尝试了这样的方法.

use Liip\FunctionalTestBundle\Test\WebTestCase;
class GenreTest extends WebTestCase {
    public function testInsert() {
        $container = $this->getContainer();
        $registry = $container->get('doctrine');
        $em = $registry->getEntityManager(null);       

        $genre = new Genre();
        $genre->setName("testGenre"); 

        $em->persist($genre);
        $em->flush();

        $result = $em->createQuery("SELECT …
Run Code Online (Sandbox Code Playgroud)

php doctrine functional-testing symfony-2.1 liipfunctionaltestbundle

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

Git不会让我合并

晚上好!

我知道这很常见,互联网上可能有成千上万的答案,但我找不到一个很好的答案.

我有两个本地分支机构:

  • MK

我对Mk进行了很多更改,提交了这些更改,并切换到MASTER以合并这两个分支.但是有冲突.所以现在我在MASTER分支上,不能再切换到Mk了,但需要用Mk覆盖我的MASTER.

它一直在说

错误:合并将覆盖对以下文件的本地更改

有没有办法做到这一点?

 git mergetool --tool=meld    #No files need merging
 git merge -s theirs Mk       #Could not find merge strategy 'theirs'.
 git merge -X recursive=theirs Mk   # error: Your local changes to the following files 
Run Code Online (Sandbox Code Playgroud)

将被合并覆盖

我还没有将我的更改推送到我的在线存储库.

我可以看到提交所有更改但无法访问其代码.

刚刚开始使用git,但从未像以前那样遇到麻烦.我真的很感激我能得到的任何帮助:s

git merge git-merge branching-and-merging

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

在 Powershell 中构建和执行命令字符串

再会!

前几天我偶然发现了一个小“问题”......

我通过 linux-shell 学习了脚本编写。在那里,人们可以通过字符串构造命令并按原样执行它们。

例如:

#!bin/bash
LS_ARGS='-lad'  
LS_CMD='ls'

CMD="$LS_CMD $LS_ARGS /home"    
$CMD
Run Code Online (Sandbox Code Playgroud)

但现在我不得不切换到Windows powershell:

If ( $BackgroundColor ) {
    Write-Host -BackgroundColor $BackgroundColor
}
If ( $ForegroundColor ) {
    Write-Host -ForegroundColor $ForegroundColor
}
If ( $ForegroundColor -AND $BackgroundColor ) {
    Write-Host -ForegroundColor $ForegroundColor
               -BackgroundColor $BackgroundColor
}

If ( $NoNewline ) {
    If ( $BackgroundColor ) { ... }
    ElseIf ( $ForegroundColor ) { ... }
    ElseIf ( $ForegroundColor -AND $BackgroundColor ) { ... }
    Else { ... }
}
Run Code Online (Sandbox Code Playgroud)

我想你知道我的意思;)有谁知道一种减少这种情况的方法,例如: …

bash powershell scripting parameter-passing

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