Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: add support of 'list' type #300

Merged
merged 1 commit into from
Oct 27, 2021

Conversation

Businesspunk
Copy link
Contributor

@Businesspunk Businesspunk commented Oct 22, 2021

TR-1351

Have added support of 'list' type and fix incorrect response in case of 'list' types

How to test (Solar)

  1. Install composer.zip
  2. Publish the test
  3. Complete the test and see the similar response in a result (in var/results)
    image
  4. Run unit-tests

*
* Copyright (c) 2013-2020 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT);
*
* @author Jérôme Bogaerts <jerome@taotesting.com>
Copy link
Contributor

@quintanilhar quintanilhar Oct 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure he is not the author of this class ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I write myself?

* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Copyright (c) 2013-2020 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Copyright (c) 2013-2020 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT);
* Copyright (c) 2021 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT);

*
* @param string $type
*/
private function setBaseType(string $type)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think both set methods can be removed as they don't provide any extra logic before assigning the value to the attribute. Wdyt?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I've removed it

@@ -201,14 +202,32 @@ public function unmarshall($json)

if (isset($v['base']) || (array_key_exists('base', $v) && $v['base'] === null)) {
$unit = ['base' => $v['base']];
$unmarshallItem = $this->unmarshallUnit($unit);
} elseif (isset($v['list']) || (array_key_exists('list', $v) && $v['list'] === null)) {
Copy link
Contributor

@quintanilhar quintanilhar Oct 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure the right side of the condition (array_key_exists('list', $v) && $v['list'] === null) makes sense for this context. I think the else condition is enough in this case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean, we can leave only check on isset there?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$arr = [];
$arr['key'] = null;
isset($arr['key']) //false

but at the right condition will be true in this keys

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but, I was in a hurry, @quintanilhar, you were right here, in this context the first condition is enough

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes @Businesspunk, that's the idea.

$listNewItems = [];

$baseType = key($list);
$listItems = $list[$baseType];
Copy link
Contributor

@quintanilhar quintanilhar Oct 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider removing this variable and using $list[$baseType] in the foreach to avoid creating another variable to hold the result "$listNewItems"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean that I have to use only $listItems variable, without creation $listNewItems ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use, you're declaring $listItems just to use in the foreach and then you have another variable $listNewItems, the "new" part sounds a bit weird. So that my proposal is to get rid of the variable $listNewItems.

$this::assertTrue($list4->equals($list5));
}

public function testToString()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public function testToString()
public function testConvertsToString()


class ListTest extends QtiSmTestCase
{
public function testEquality()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider creating 2 tests for the different outputs:

testReturnsTrueWhenListIsEqualTo
testReturnsFalseWhenListIsDifferent

@Businesspunk Businesspunk force-pushed the feature/TR-1351/add-supporting-of-list-type branch 2 times, most recently from f53cbc4 to 57d3aad Compare October 22, 2021 16:25
@Businesspunk Businesspunk force-pushed the feature/TR-1351/add-supporting-of-list-type branch from 57d3aad to 9b9debc Compare October 25, 2021 08:22
Copy link
Contributor

@poyuki poyuki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • New code is covered by tests (if applicable)
  • Tests are running successfully (old and new ones) on my local machine (if applicable)
  • New code is respecting code style rules
  • New code is respecting best practices
  • New code is not subject to concurrency issues (if applicable)
  • Feature is working correctly on my local machine (if applicable)
  • Acceptance criteria are respected
  • Pull request title and description are meaningful
  • Pull request's target is not master
  • Commits are following conventional commits
  • Changelog is updated according to changes (if applicable)
  • Documentation is updated according to changes (if applicable)

Copy link
Member

@julien-sebire julien-sebire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you'll need the counterpart in src/qtism/pci/json/Marshaller.php

* @license GPLv2
*/

namespace qtism\common\datatypes;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand why you do it this way, but it makes it look like QtiList is a base type. Well, maybe we can do it this way for the sake of simplification, but at least, mention that it's a convenience and kept in qtism/common/datatype for the sake of simplicity.

@Businesspunk Businesspunk force-pushed the feature/TR-1351/add-supporting-of-list-type branch 4 times, most recently from 423ab79 to 0c67545 Compare October 26, 2021 15:24
Copy link
Contributor

@quintanilhar quintanilhar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, extract the existing implementation to a new method and use it in the record list parsing.

@@ -375,4 +375,29 @@ public function unmarshallInvalidProvider()
['{ "record" : [ { "namez" } ] '],
];
}

public function testUnmarshallListType()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public function testUnmarshallListType()
public function testUnmarshallListWithinRecord()

Copy link
Contributor

@poyuki poyuki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • New code is covered by tests (if applicable)
  • Tests are running successfully (old and new ones) on my local machine (if applicable)
  • New code is respecting code style rules
  • New code is respecting best practices
  • New code is not subject to concurrency issues (if applicable)
  • Feature is working correctly on my local machine (if applicable)
  • Acceptance criteria are respected
  • Pull request title and description are meaningful
  • Pull request's target is not master
  • Commits are following conventional commits
  • Changelog is updated according to changes (if applicable)
  • Documentation is updated according to changes (if applicable)

@Businesspunk Businesspunk force-pushed the feature/TR-1351/add-supporting-of-list-type branch 3 times, most recently from bf9f207 to 64f4e91 Compare October 27, 2021 10:01
*
* @param array $parsedJson
* @return MultipleContainer
* @throws FileManagerException
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this exception is not thrown here. Can you confirm, please?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IF type in 'list' will be file it can be

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unmarshallFile will be called, which can throw this exception

@Businesspunk Businesspunk force-pushed the feature/TR-1351/add-supporting-of-list-type branch from 64f4e91 to 947ccb5 Compare October 27, 2021 10:25
Copy link
Contributor

@quintanilhar quintanilhar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • New code is covered by tests (if applicable)
  • Tests are running successfully (old and new ones) on my local machine (if applicable)
  • New code is respecting code style rules
  • New code is respecting best practices
  • New code is not subject to concurrency issues (if applicable)
  • Feature is working correctly on my local machine (if applicable)
  • Acceptance criteria are respected
  • Pull request title and description are meaningful
  • Pull request's target is not master
  • Commits are following conventional commits
  • Commits messages are meaningful
  • Commits are atomic
  • Changelog is updated according to changes (if applicable)
  • Documentation is updated according to changes (if applicable)

@Businesspunk Businesspunk merged commit e2b4132 into develop Oct 27, 2021
@Businesspunk Businesspunk deleted the feature/TR-1351/add-supporting-of-list-type branch October 27, 2021 12:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants