php 使用Transaction进行Laravel DB测试

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 使用Transaction进行Laravel DB测试相关的知识,希望对你有一定的参考价值。

<?php

class ExampleTest extends TestCase {
	
	public function setUp()
	{
		parent::setUp();
		
		DB::beginTransaction();
	}
	
	/**
	 * A basic functional test example.
	 *
	 * @return void
	 */
	public function testShowsPosts()
	{
	        $title = 'Yay Great Post';
	
	        // "Create" post
	        Post::create(compact('title'));
	
	        $crawler = $this->client->request('GET', 'posts');
	
	        $this->assertEquals(
	            1,
	            count($crawler->filter("body:contains('{$title}')")),
	            "Expected to see the text '{$title}' within a body element."
	        );
	}
}

以上是关于php 使用Transaction进行Laravel DB测试的主要内容,如果未能解决你的问题,请参考以下文章

larave Elasticsearch scout Unsupported operand types报错

手把手教你跑Larave框架实战笔记系列之二

Laravel DB::transaction 不回滚异常

larave学习笔记1-安装配置

php [php:PDO transaction]示例代码。 #PHP

php PHP:livetpl.transaction