propelorm / Propel2

Propel2 is an open-source high-performance Object-Relational Mapping (ORM) for modern PHP
http://propelorm.org/
MIT License
1.26k stars 399 forks source link

Timestamp Getter Function Returns Null Running CLI (PHPUnit) #1744

Open abdyek opened 3 years ago

abdyek commented 3 years ago

This is part of my schema.xml

<table name="authentication">
    <column name="id" type="integer" required="true" primaryKey="true" autoIncrement="true"/>
    <column name="type" type="varchar" size="20" required="true"/>
    <column name="code" type="varchar" size="20" required="true"/>
    <column name="date_time" type="timestamp" required="true" defaultExpr="CURRENT_TIMESTAMP"/>
    <column name="count" type="integer" size="3" required="true" default="0"/>
    <column name="member_id" type="integer" required="true"/>
    <foreign-key foreignTable="member">
        <reference local="member_id" foreign="id"/>
    </foreign-key>
</table>

$timestamp = $auth->getDateTime(); $timestamp variable is null. I tried another name but it always returns null. I used propel2 for several project but I didn't see a bug like this. Is there a config for it or it is a bug?

My TestClass:


require 'propel/config.php';
use PHPUnit\Framework\TestCase;
use SholistApi\Controller\Example;

class ExampleTest extends TestCase {
    use ResetDatabase;
    public function testCreate() {
        $example = new Example([
            'method'=>'GET',
            'data'=>[],
            'who'=>'guest',
            'id'=>null
        ]);
        $example->create();
        $auth = \Authentication::getById(1);
        $this->assertEquals(1, $auth->getId());
        $this->assertEquals('this is type', $auth->getType());
        $this->assertNotNull($auth->getDateTime());
    }
}

My Controller Class:


namespace SholistApi\Controller;
use SholistApi\Core\Controller;

class Example extends Controller {
    protected function get() {
    }
    public function create() {
        $member = \Member::create([
            'email'=>'yunusemrebulut123@gmail.com',
            'password'=>'12312312',
            'registeredByGoogle'=>false,
            'deviceId'=>'Bw9ru9H59Ec5umfDCP2Hu5VY6qfKDzEferyh'
        ]);
        $auth = \Authentication::create([
            'memberId'=>$member->getId(),
            'code'=>'123123',
            'type'=>'this is type'
        ]);
    }
}

PHPUnit Output:

PHPUnit 8.5.15 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.0.6
Configuration: /opt/lampp/htdocs/sholist-api/phpunit.xml

F                                                                   1 / 1 (100%)

Time: 333 ms, Memory: 6.00 MB

There was 1 failure:

1) ExampleTest::testCreate
Failed asserting that null is not null.

/opt/lampp/htdocs/sholist-api/tests/unit/Controller/ExampleTest.php:20

FAILURES!
Tests: 1, Assertions: 3, Failures: 1.
mringler commented 3 years ago

Impossible to say without examining the code and the database. Only you can do that. Have you checked all the places where this might go wrong (i.e. does the row in the database have a value, does the Propel statement fetch this value, what is accessed in getDateTime(), etc.)? If this turns out to be a bug, please report it.

abdyek commented 3 years ago

Impossible to say without examining the code and the database. Only you can do that. Have you checked all the places where this might go wrong (i.e. does the row in the database have a value, does the Propel statement fetch this value, what is accessed in getDateTime(), etc.)? If this turns out to be a bug, please report it.

date_time is a column in authentication table and there is xml skeleton first message. getDateTime function must return this column normally. But it returned null. I think maybe this issue is about php runtime. I suspend date_time test code in my project for now. Yes I have checked all the places for this issue. Thank you by the way..