0

I have a question,

I am using phpunit WebTestCase in symfony 3.4

but I can't select any data

and I get

1) Tests\BankBundle\Controller\BankControllerTest::testmoneyIn Failed asserting that null matches expected 1.

I follow this Tutorial

this is my ControllerTest

<?php
namespace Tests\BankBundle\Controller;
use BankBundle\Entity\entry;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class BankControllerTest extends WebTestCase
{
    /**
     * @var \Doctrine\ORM\EntityManager
     */
    private $em;

    /**
     * {@inheritDoc}
     */
    public function setUp(): void
    {
        static::$kernel = static::createKernel();
        static::$kernel->boot();
        $this->em = static::$kernel->getContainer()
            ->get('doctrine')
            ->getManager();
    }

    public function testmoneyIn()
    {
        $client = static::createClient();
        $client->request('POST', '/bank/moneyin', array('amount' => 50));
        $bank = $this->em
            ->getRepository('BankBundle:entry')
            ->getId(1);

        $this->assertEquals(1, $bank);
    } 

    /**
     * {@inheritDoc}
     */
    protected function tearDown(): void
    {
        parent::tearDown();
        $this->em->close();
    } 
}
1
  • You are trying to assert that$bank = 1. But $bank is null. Your test is failed Commented Oct 4, 2019 at 5:34

1 Answer 1

0

You are trying to assert that $bank = 1. But $bank is null. Your test failed. For test use, you should always use predictable data. That means, whenever you run the test, you know the expected result. So, you are sure that if your assertion failed, that means, your code is wrong.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank for your Suggest. I will try it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.